Results 1 to 7 of 7
  1. #1
    oontvoo is offline Member
    Join Date
    May 2010
    Posts
    23
    Rep Power
    0

    Default Class Not Found Exception when trying to open a .jar file

    I've been encountering this exceptions recently. My java program would work just fine if I run it from the IDE or via command line (run the .class file). But when I use the IDE (netbeans) make an executable file (.jar), the program doesn't run at all. It says something like "Class Not Found Exception" or "No Class Definition Found"...
    I do not problem lies with my code. It's probably just the java configuration on my PC...

    So what should I do to fix this?

    Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Open a command prompt, change to the folder with the jar file and enter:
    java -jar <YOURJARFILENAME>.jar
    Copy the console window and paste here.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  4. #4
    ignisfatuus is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default

    I've seen this a lot in NetBeans. This happens when you move/rename your main class after initial project creation. Even when doing a move or rename through refactoring, NetBeans does not update the main class namespace for the project (which is written to the jar manifest file when building).

    To select the new main class, right-click on your project in the projects pane, go to properties. Go to the 'run' category on the left hand side, then click browse next to Main Class. It should only display your main class, unless you have multiple classes in the project with a main() method. Select the proper class, close out of the dialog, and run a clean and build on the project.

    Assuming this is the problem, you should be able to run the jar using 'java -jar JarName.jar'

    Not enough info given to be sure this is the issue, but like I've said, I've run into this a lot. Hope it helps :)

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Does your .jar file even have a manifest entry and is it pointing to the class that contains the static main( ... ) method?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    jing-yi is offline Member
    Join Date
    May 2011
    Posts
    35
    Rep Power
    0

    Default

    Is that possible you are facing jar hell issue?

    If you suspect this, probably you need to use verbose option to verify this.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by jing-yi View Post
    Is that possible you are facing jar hell issue?

    If you suspect this, probably you need to use verbose option to verify this.
    (Ignoring the fact the OP posted this over a week ago...:))
    What is "jar hell"?
    Since an exeutable jar contains its own classpath (in the manifest) there should be no reason to have incorrect jar versions being pulled in.

Similar Threads

  1. Class not found Exception
    By surendra in forum Java Servlet
    Replies: 8
    Last Post: 06-09-2011, 01:52 PM
  2. File not found exception on ObjectInputStream
    By pink123 in forum New To Java
    Replies: 8
    Last Post: 06-08-2011, 05:00 PM
  3. No Property Editor Found Exception -JSF 1.2
    By venkatcanwin in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-18-2010, 07:02 AM
  4. How do I open a file with a class, or can I?
    By bobleny in forum New To Java
    Replies: 4
    Last Post: 04-02-2009, 10:59 AM
  5. class not found exception while using IKVM to create exe for c#
    By manjunath k reddy in forum New To Java
    Replies: 0
    Last Post: 02-21-2009, 07:05 AM

Posting Permissions

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