jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes ClassNotFoundException on main class in executable Jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ClassNotFoundException on main class in executable Jar file" Watch "ClassNotFoundException on main class in executable Jar file" New topic
Author

ClassNotFoundException on main class in executable Jar file

Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 642
I'm having a problem getting an application to run when packaged as an executable Jar file (java -jar MyJar.jar).
The application needs to reference an external Jar file (javamail-1.4's mail.jar). When I include that Jar on the Class-Path attribute of the Manifext.mf file, then I get a ClassNotFoundException on my main class. Without the class-path entry, my main class is found just fine (but of course it can't find the javamail stuff...).

First, here is the structure of my application's Jar file:


Here is the contents of my meta-inf/Manifest.mf file:



When the Manifest.mf file includes a Class-Path entry, is there something special I need to do to get the classes in my Jar on the class path as well?

I'm assuming I'm doing something silly, but after pouring over several tutorials/examples, I just don't see it.

Thanks,
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 642
Well, I decided to try copying the external jar into a directory relative to the location of my application's Jar file and changing the Class-Path entry in the Manifest.mf file accordingly, and it now works. Perhaps the Class-Path entry of the Manifest.mf file can't accept full-paths (or Windows full-paths)?

If there's a way to have my application refer to an external Jar that is referenced via a full Windows path, I would sure appreciate knowing how to do it. I would rather not make copies of the external Jars if I can help it.

Thanks,
Esmaeil Ashrafi
Ranch Hand

Joined: Feb 22, 2010
Posts: 73
Did you noticed that MS Windows file system uses back slash ("\") character instead of slash ("/") !?

I'm not sure, but you can try it and also you can use extension mechanism...


I'm really tired of being engaged with stuff other than Java and programming

Wish to get back soon to my love...
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Esmaeil Ashrafi wrote:Did you noticed that MS Windows file system uses back slash ("\") character instead of slash ("/") !?

No, that's not correct. The backslash is Windows specific, the forward slash is universal. Open a command prompt in Windows and try a cd command with a forward slash to see for yourself.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException on main class in executable Jar file
 
Similar Threads
Declaring library dependency in war
why is this happening REALLY URGENT
Help with building executable jar with ant.
using an executable jar file
Jar in a Jar