Sunday, April 30, 2006

JAR and classpath

Arghhhhh, this just cost me about 2hrs...
When running a Java application packaged into my own JAR from the command line with

java -classpath /somepath/library.jar -jar myJar.jar

it just wouln't pick up the library.jar.

You can specify a Class-Path entry in the manifest for your own jar, but thats only used to references jars within your jar, not really external jars.

No matter what I did, I would always get a java.lang.NoClassDefFoundError.

Here's the entry in Sun's Java Forum that finally solved it for me - I quote from the post:

When the -jar option is used, the -classpath or any system classpath is ignored - the only classpath is the one in the manifest of the executable jar file, if specified.

Would it hurt to properly document this ??

No comments: