Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java execute jar which depends on other jar from command line

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?

like image 674
Cratylus Avatar asked Feb 26 '23 10:02

Cratylus


2 Answers

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.

like image 96
krock Avatar answered Mar 05 '23 17:03

krock


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.

like image 28
stacker Avatar answered Mar 05 '23 16:03

stacker