.jar issues

Discussion in 'Mac Programming' started by Rhalliwell1, May 17, 2009.

  1. Rhalliwell1 macrumors 6502a

    Joined:
    May 22, 2008
    #1
    I have written a little java app and packaged it up into a .jar but when i try to run it i get the following message:
    [​IMG]

    So i check the console and i get this:

    [​IMG]

    Any suggestions?
    I have downloaded and re-installed the latest version of java from apple. The app does run through netbeans.
     
  2. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #2
    post the result of typing in Terminal: jar -tfv addressBook.jar

    Also, how did you create the jar? Did you use NetBeans to do it? Doing it by hand is often error prone.
     
  3. Rhalliwell1 thread starter macrumors 6502a

    Joined:
    May 22, 2008
    #3
    Robs-iMac:addressbook roberthaliwell$ java -jar addressBook.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: book (wrong name: addressbook/book)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
    Robs-iMac:addressbook roberthaliwell$ jar -tfv addressBook.jar
    0 Sun May 17 17:12:50 BST 2009 META-INF/
    78 Sun May 17 17:12:50 BST 2009 META-INF/MANIFEST.MF
    2895 Tue Jan 01 00:00:00 GMT 1980 Contact.class
    1011 Tue Jan 01 00:00:00 GMT 1980 ContactList.class
    11658 Tue Jan 01 00:00:00 GMT 1980 book.class
     
  4. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #4
    It looks like you just jarred the classes up by hand. Did you? The book.class in the jar file should be address/book.class, from the error message you're getting.

    How did you build it? If you're using NetBeans, Shift-F11 will build the jar file automatically. Look at the console output to see its location.

    (Sorry I didn't respond with more detail before ... it's been a while since I used NetBeans ... I just created and built a HelloWorld.jar from NetBeans and it works fine)
     
  5. Rhalliwell1 thread starter macrumors 6502a

    Joined:
    May 22, 2008
    #5
    i followed these instructions. i searched in the help of netbeans and couldn’t find anything with "jar" in so gave up! Thanks for the tip :D
     
  6. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #6
    Yeah, well, those instructions don't mention the package name, which in your case is addressbook. This is better: http://www.javacoffeebreak.com/faq/faq0028.html

    But just use the NetBean generated jar, unless you want to get into the details of how you do this.

    By the way, you should try to follow the Java conventions ... all classes should be named camel case - ie like how you named ContactList. So 'book' should be Book.
     

Share This Page