This discussion is archived
6 Replies Latest reply: Mar 31, 2012 8:58 AM by rukbat RSS

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/javacard

843851 Newbie
Currently Being Moderated
Hello,

I am working on JavaCard 2.2.1 compliant card and JavaCard SDK 2.2.1. I have already developed(via Eclipse with no JavaCard plugin) an applet which I have compiled successfully(via JDK 1.4.07 since this is the suggested version in Sun's Development Kit User’s Guide for Java Card 2.2.1).

The next step for me is to create the CAP file and load it on the card. When I tried to use the converter, I encountered the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/javacard/converter/Converter

User safarmer has suggested previously in this post that I should set my environment variable JC_HOME to the jcdk's directory. I have already assigned this Environment Variable under System Variables as it states in the user guide(I tried to stick to the steps there as much as possible).

Maybe there is a mistake in my command?

The following is my input command:

converter -applet 0xAB:0xCD:0xEF:0x12:0x34 EmpApplet -classdir c:\java_card_kit-2_2_1\bin -out CAP -d C:\output\ EmpApplet 0xAB:0xCD:0xEF:0x12:0x34 1.0

Format:

converter -applet <Applet AID> <Class Name> -classdir <directory of the classes> -out <output type> -d <output directory> <Package name> <Package AID> <major version>.<minor version>


I get the same error even when I don't pass any arguments at all.


Is there a way anyone could guide me? If there is another way to create the CAP file and load it on a card that is compliant to JC2.2.1 specs, that would also be much appreciated.



P.S: Mod PhHein, I apologize, but this thread was the only relevant post I found over google. I also want to ask you what you mean by "hijacking" a post? Do you mean I can't continue asking relevant questions under a previous post? Wouldn't that create too many duplicate threads?Please advise so I won't show any inconvenient forum behaviour.Thank you.
  • 1. Re: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/javacard
    safarmer Expert
    Currently Being Moderated
    Hi,

    This error is from the Java run time not finding the main class the shell script tries to execute. You could try adding some debug output to the shell script (or batch file on Windows) to see what is being picked up by the script.
    From Linux JCDK:
    $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.converter.Converter "$@"
    Since the class not being found is the one being passed to the Java executable the converter.jar is either not being found or is corrupt. You can test the jar with "jar -tf converter.jar" in the JC_HOME/lib directory. Make sure the class com.sun.javacard.converter.Converter is listed.

    Cheers,
    Shane
  • 2. Re: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/javacard
    843851 Newbie
    Currently Being Moderated
    First of all, thank you for taking the time to reply. I also apologize I haven't given any feedback for some time as I was busy with some other responsibilities I had.

    That being said;

    I checked the folders, converter.jar is under "C:\java_card_kit-2_2_1\lib" and converter.bat is under "C:\java_card_kit-2_2_1\bin"

    After I tried "jar -tf converter.jar" in the JC_HOME/lib directory I got a list of class files which is in the JAR File. I believe this proves the JAR file is ok. Right?

    Whatever the parameters I am passing, it is showing this same error I stated earlier.



    You also told me to add a debug output to the batch file. I opened the bat file as txt file. But where should I add the "-debug" syntax?
  • 3. Re: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/javacard
    safarmer Expert
    Currently Being Moderated
    Hi,

    I meant to add echo statements to the batch file. You could also try calling the java command directly (as the batch file does). Since the JAR file seems to be OK, there is something wrong with either your environment variables or batch file. I am assuming the batch file has not been changed so this should not be the problem. The converter is just a Java application so it is the same mechanism as running any Java application from a JAR file.

    Cheers,
    Shane
  • 4. Re: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/javacard
    843851 Newbie
    Currently Being Moderated
    I have done as you said.

    I modified the .bat file where it had the echo off. I set that to on. Then I ran the command again. I did't understand what output it was giving me so I turned it back off.
    I also checked the environment variables. I saw everything was in order but I still deleted and recreated them, maybe I missed something.

    Then I tried my command again and started getting other parameter related errors. I have resolved those also. I don't know what actually solved the issue, but thank you very much.I really appreciate the suggestions.
  • 5. Re: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/javacard
    927676 Newbie
    Currently Being Moderated
    run this one in command prompt and then convert the applet using converter tool


    JC_HOME = C:\java_card_kit-2_2_2\bin\

    set CLASSES=%JCHOME%\lib\apduio.jar;%JC_HOME%\lib\apdutool.jar;%JC_HOME%\lib\jcwde.jar;%JC_HOME%\lib\converter.jar;%JC_HOME%\lib\scriptgen.jar;%JC_HOME%\lib\offcardverifier.jar;%JC_HOME%\lib\api.jar;%JC_HOME%\lib\installer.jar;%JC_HOME%\lib\capdump.jar;

    D:\NareshPalle\jcardRE\Smart\src>java -classpath %_CLASSES% com.sun.javacard.con
    verter.Converter -out EXP JCA CAP -exportpath .\exp -applet 0x0a:0x00:0x00:0x00:0x0e:0x01:0x02:
    0x03:0x04:0x05:0x06 PackageName appletName 0x01:0x02:0x03:0x04:0x05:0x0
    6:0x07:0x08 1.0

    or

    go to following directory and run the converter tool in command prompt

    step 1: cd C:\java_card_kit-2_2_2\bin\

    then run this command under the above directory

    step 2:converter -classdir E:\Pathof Your applet class file -out EXP JCA CAP -exportpath E:\path of exp files folder -applet AID PackageName AppletName PackAID major.minor no


    For more doubts mail me....

    *[removed by moderator]*




    Thanks and Regards

    NareshPalle

    Edited by: EJP on 31/03/2012 20:09: removed your email address. Unless you like spam and unless you think these forums are provided for your personal benefit only, posting an email address here serves no useful purpose whatsoever.
  • 6. Re: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/javacard
    rukbat Guru Moderator
    Currently Being Moderated
    2010 posting to a Sun Microsystems forum
    by someone that never re-registered when Oracle folded all the threads into its forum site.

    Resurrected in 2012.

    Locking to prevent another attempt at a resurrection.