4

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?

2 Answers 2

6

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.

2
  • 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?
    – Cratylus
    Commented Aug 18, 2010 at 7:10
  • 2
    You must use Export -> Runnable Jar for this. Commented Aug 18, 2010 at 8:48
2

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.

3
  • Tried as you said: java -cp cab.v1.jar -jar myApp.jar but still same error. Note that both jars are in the same directory
    – Cratylus
    Commented Aug 18, 2010 at 6:42
  • @user38706 I wrote that you can't use -jar and -cp together. Here are several options: mindprod.com/jgloss/classpath.html
    – stacker
    Commented Aug 18, 2010 at 6:53
  • 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?
    – Cratylus
    Commented Aug 18, 2010 at 7:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.