Results 1 to 4 of 4
  1. #1
    eLancaster is offline Member
    Join Date
    Jan 2011
    Posts
    93
    Rep Power
    0

    Default .jar file cant find main class

    ok, i made a game which consisted of two java files:
    - BettingGame.java
    - BettingGame_MainClass.java.

    I compiled them and got:
    - BettingGame.class
    - BettingGame$Listener.class
    - BettingGame_MainClass.class

    I threw in a manifest file stating the following

    Java Code:
    Main-Class: BettingGame_MainClass\n
    \n
    and created the .jar file in terminal with the following command:
    Java Code:
     jar cfm BettingGame.jar manifest.txt BettingGame_MainClass.class BettingGame.class BettingGame$Listener.class
    and i succesfully got a .jar file.

    When I tried to run the .jar file using:

    Java Code:
    [java -jar BettingGame.jar
    I get the following errors


    Exception in thread "main" java.lang.NoClassDefFoundError: BettingGame$Listener
    at BettingGame.<init>(BettingGame.java:60)
    at BettingGame_MainClass.main(BettingGame_MainClass.j ava:6)
    Caused by: java.lang.ClassNotFoundException: BettingGame$Listener
    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 21)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 66)




    Where did i go wrong?
    I followed the steps from this video: YouTube - How to create Java executables/jar file
    Last edited by eLancaster; 02-09-2011 at 07:41 PM.

  2. #2
    eLancaster is offline Member
    Join Date
    Jan 2011
    Posts
    93
    Rep Power
    0

    Default

    P.S. The java program itself works fine. it compiles and runs with no errors.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,051
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by eLancaster View Post
    Where did i go wrong?
    You can inspect the .jar file with e.g. winzip; check if that nested class made it in your .jar file. According to the exception stack trace, it didn't.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  4. #4
    eLancaster is offline Member
    Join Date
    Jan 2011
    Posts
    93
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 11-11-2010, 09:12 AM
  2. Jar file could not find the main class
    By Collinryans in forum New To Java
    Replies: 3
    Last Post: 06-23-2010, 04:18 AM
  3. Could not find main class
    By Andyj in forum New To Java
    Replies: 2
    Last Post: 10-06-2009, 12:47 AM
  4. Replies: 1
    Last Post: 07-03-2009, 08:41 PM
  5. Could not find main class - JDK 1.6
    By Syranno in forum New To Java
    Replies: 1
    Last Post: 07-25-2008, 04:07 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
  •