views:

528

answers:

3

I've run in to a strange error with the javamail 1.4.2 api and jdk/jre 1.6.0u16. I've placed the unzipped javamail-1.4.2 folder (along with the MySQL Connector-J 5.1.7 also needed) in both the jdk and jre folders as in the %classpath% below.

.;"C:\Program Files\Java\jdk1.6.0-16\jre\lib\ext\mysql-connector-java-5.1.7-bin";"C:\Program Files\Java\jdk1.6.0-16\jre\lib\ext\javamail-1.4.2\mail.jar";"C:\Program Files\Java\jdk1.6.0_16\bin";"C:\Program Files\GameLabInventory\GameLabInventory-7.0.jar";"C:\Program Files\Java\jre6\lib\ext\mysql-connector-java-5.1.7-bin";"C:\Program Files\Java\jre6\lib\ext\javamail-1.4.2\mail.jar";

But when I run my compiled jar with the command

C:\Program Files\Java\jre6\bin>java -cp %classpath% -jar "C:\Program Files\GameLabInventory\GameLabInventory_7.0.jar"

I get the following error message:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException at gamelab.inventory.GameLabInventory.main(GameLabInventory.java:62) Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) ... 1 more

I can't find anything wrong with my setup here, hopefully you guys can help me out. Thanks!

Here is the manifest file:

Manifest-Version: 1.0
Main-Class: gamelab.inventory.GameLabInventory

Here is the jar -tvf (link)

+1  A: 

When using -jar, java overrides the classpath setting (-cp). In this configuration, however, classpath jars can be specified in the manifest file of your jar.

jsight
I'll try this out, but how should I put the paths in? Do I add the two jar files into the main program's jar and add them with no path? Or is there a way to do it with relative paths outside the jar file?
Kevin Stich
Just add them with relative paths to the jar itself. Actually, why are you putting these jars in subdirs of ext in JDK home anyway? Thats a really strange place to put them, imo. If you just put the jar files in lib/ext they would automatically be picked up.
jsight
+1  A: 

According to the documentation for the java tool:

When you use [the -jar] option, the JAR file is the source of all user classes, and other user class path settings are ignored.

You can specify a Class-Path attribute in yourJAR file that "specifies the relative URLs of the extensions or libraries that [your] application or extension needs."

Brandon E Taylor
I'll try this out, but how should I put the paths in? Do I add the two jar files into the main program's jar and add them with no path? Or is there a way to do it with relative paths outside the jar file?
Kevin Stich
After a bunch of fiddling, a specified class-path was eventually the solution.
Kevin Stich
A: 

I've experienced a similar issue (not identical to yours, since mine is spring-related) and found this link was helpful:

http://forum.springsource.org/showthread.php?t=65840&page=3

It seems that implementation changes in the JDK might be causing this behaviour. Quoting from the link:

"I managed to reproduce the problem on my Mac development box using Java 6 (1.6.0_07). I then tried it on my Mac using Java 5, and could not reproduce the problem. Crucially, in the Java 5 case, the JVM would be using the javax.activation API and implementation from the 1.1.1 javax activation bundle, whereas on Java 6, it would be using them from the JRE (anything that's part of the JRE takes precedence over what's in dm Server's lib directory). I then tried the app on an Ubuntu box, this time using Java 6 1.6.0_10. I could not reproduce the problem."

and/but:-

"I've just had this same problem "No object DCH for MIME type" but on Ubuntu java version "1.6.0_13". So I don't know how you guys solved it by upgrading to 1.6.0_11. What I did is copy the mailcab.default to my own bundle and it worked. Seems to be a classloading problem which I don't fully understand yet."

davek