• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException on main class in executable Jar file

 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic