Results 1 to 7 of 7
  1. #1
    Join Date
    May 2011
    Posts
    6
    Rep Power
    0

    Default Error in jar file but not when program is run as standalone

    Hello,

    I created a program in java when i compile it javac filename.java and run it java filename using the command line it runs perfectly. The problem I am having is when i make a jar file using this command line jar cfm filename.jar man.tx filename.class filename.png it creates the jar file filename.jar but when i try and run it using this command line java -jar filename.jar it gives me these errors:

    Exception in thread "main" java.lang.NoClassDefFoundError: SchoolVue$1
    at SchoolVue.RunSchool(SchoolVue.java:97)
    at SchoolVue.main(SchoolVue.java:560)
    Caused by: java.lang.ClassNotFoundException: SchoolVue$1
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 19)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 64)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:332)

    I've even created a manifest file that contains Main-Class: className and it still doesn't work.
    Does anyone have a clue as to why this is happening?
    Last edited by lance9200@yahoo.com; 05-18-2011 at 05:20 PM. Reason: needed to include more information for better understanding

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    Can you elaborate all steps how you make your JAR?
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    i make a jar file using this command line jar cfm filename.jar man.tx filename.class filename.png
    You have to include all .class files. Including those with names like filename$1.class, filename$1.class etc. Those are the class files for your anonymous inner classes.

    But first, you should have looked at the stack trace.
    ... NoClassDefFoundError: SchoolVue$1
    at SchoolVue.RunSchool(SchoolVue.java:97)
    What's on line 97 of SchoolVue.java? I'll bet there's a new ... statement which tries to instantiate the first declared anonymous inner class.

    db

  4. #4
    Join Date
    May 2011
    Posts
    6
    Rep Power
    0

    Default

    I give descriptions how I created the jar file in the original post as well as how I created the class file with javac. But here it is again:

    jar cfm jarfile.jar man.txt classFile.class picture.png

    line 97 is the end of an actionlistener { ); } i surrounded it in curly braces

  5. #5
    Join Date
    May 2011
    Posts
    6
    Rep Power
    0

    Default

    When class file is created does it create a second class file with $1 appended to it?

  6. #6
    Join Date
    May 2011
    Posts
    6
    Rep Power
    0

    Default

    Thank you very much I created a new jar file and include the name of class file with the $1 appended and it worked. Bless you. I've been trying to figure this out for 2 days.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default

    When you compile a java file that contains anonymous classes in it it will create a class file for each of those anonymous ones, appending $n to the end (where n increments).

    Similarly for named inner classes, where the class file produce will be called <parentclassname>$<innerclassname>.class.

Similar Threads

  1. Replies: 3
    Last Post: 11-11-2010, 08:12 AM
  2. File upload from standalone client
    By Astghik in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 01-12-2010, 02:07 PM
  3. java standalone to applet
    By Nikohw in forum Java Applets
    Replies: 1
    Last Post: 09-15-2009, 09:36 AM
  4. Standalone applications
    By sachin2 in forum New To Java
    Replies: 0
    Last Post: 07-21-2009, 08:08 PM
  5. Replies: 1
    Last Post: 07-03-2009, 08:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •