This discussion is archived
5 Replies Latest reply: Nov 13, 2012 9:33 AM by safarmer RSS

Java Card program execution on Eclipse

973620 Newbie
Currently Being Moderated
Hi Dears,

I am new to Java Card. I did setup to run Java Card programs on eclipse using http://eclipse-jcde.sourceforge.net/.

This is my simple program below

import javacard.security.RandomData;

public class Main {

     public void main() {
                              
          RandomData rd = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
          
          short outLen = 10;
          byte buffer[] = new byte[outLen];
          short outOffset = 0;
                    
          rd.generateData(buffer, outOffset, outLen);

     }

}

Compilation is successful but when I run the program I get the following error.

Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/String

This is very annoying. I think my run time environment is not ok for running java card programs. I am able to run Java programs but not java card programs. Any one can help please?

Thanks,

Regards,
Naveed
  • 1. Re: Java Card program execution on Eclipse
    973833 Newbie
    Currently Being Moderated
    Hello,

    class String is not available on Java cards, for a first applet you should try with an example from a tutorial (and no main for applets)

    Gilles
  • 2. Re: Java Card program execution on Eclipse
    safarmer Expert
    Currently Being Moderated
    please post code with {code} tags
    Naveed86 wrote:
    Hi Dears,

    I am new to Java Card. I did setup to run Java Card programs on eclipse using http://eclipse-jcde.sourceforge.net/.

    This is my simple program below
     
    import javacard.security.RandomData;
    
    public class Main {
    
         public void main() {
                                  
              RandomData rd = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
              
              short outLen = 10;
              byte buffer[] = new byte[outLen]; 
              short outOffset = 0;
                        
              rd.generateData(buffer, outOffset, outLen);
    
         }
    
    }
    Compilation is successful but when I run the program I get the following error.

    Error occurred during initialization of VM
    java/lang/NoClassDefFoundError: java/lang/String

    This is very annoying. I think my run time environment is not ok for running java card programs. I am able to run Java programs but not java card programs. Any one can help please?

    Thanks,

    Regards,
    Naveed
  • 3. Re: Java Card program execution on Eclipse
    safarmer Expert
    Currently Being Moderated
    How do you run your application? Have you loaded onto a card or emulator?

    - Shane
  • 4. Re: Java Card program execution on Eclipse
    973620 Newbie
    Currently Being Moderated
    I am running on Eclipse.
  • 5. Re: Java Card program execution on Eclipse
    safarmer Expert
    Currently Being Moderated
    Hi,

    The JC API jar files do not have a real implementation as it is provided by the JCRE. You need to load the file as an applet onto an emulator or a real card. Then the only way to interact with the code is through APDU's.

    You could implement stub/dummy implementations for the JC API if you want to run as a unit test though.

    - Shane

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points