views:

85

answers:

2

Hi,

I have an application that uses an external jar. I used eclipse and it works fine. I export as jar from eclipse, having created a Manifest file that has as Class-Path: ./cab.v1.jar I place both jars in the same directory. I run in command line: java -jar myApp.jar

and get java.lang.NoClassDefFoundError for the classes in the cab.v1.jar (the other jar) Have also tried java -cp . -jar myApp.jar but no success. What am I doing wrong?

+4  A: 

Using the documentation for the Manifest it does not use a ./ for relative directories. Try it just with:

Class-Path: cab.v1.jar

Note that the -cp option is ignored when using -jar.

krock
@krock: Thank you. I tried it, did not work but then extracted jar and saw that eclipse is not using my placing the class-path in the maninifest file. Did it manually and it works. Any idea why eclipse does this?
You must use Export -> Runnable Jar for this.
Thorbjørn Ravn Andersen
@Ravn Andersen: Thank you!!! With runnable jar it worked!
+1  A: 

If you use the -jar option the classpath is ignored. You could start the application by

java -cp jar1.jar:jar2.jar mainclass

The class path separator ':' is ';' on windows.

stacker
@stacker: Tried as you said:java -cp cab.v1.jar -jar myApp.jarbut still same error. Note that both jars are in the same directory
@user38706 I wrote that you can't use -jar and -cp together. Here are several options: http://mindprod.com/jgloss/classpath.html
stacker
@stacker: Sorry, my bad. Anyway I extracted jar and saw that eclipse is not using my placing the class-path in the manifest file. Did it manually and it works. Any idea why eclipse does this?