Running jar from another directory cannot find the required dependency

I am trying to run jar ec/mobat/MOBAT.jar , which depends on some jars located in ec/mobat/lib/ . It works if I do:

 ec/mobat/$ java -jar MOBAT.jar 

However, I want to be able to run the jar from another directory

 ec/$ java -jar mobat/MOBAT.jar 

But I get an exception

 java.lang.NoClassDefFoundError: ibis/io/Serializable ... 

I tried to pass the necessary banks on the way to the classes

 ec/$ CLASSPATH=... java -jar mobat/MOBAT.jar ec/$ java -jar -cp ... mobat/MOBAT.jar 

but I get exactly the same exception. Any fix?

Update : MANIFEST.INF contains the following:

 Manifest-Version: 1.0 Ant-Version: Apache Ant 1.7.0 Created-By: Selmar Kagiso Smit Main-Class: mobat.Launcher Implementation-Version: 1.3.4 
+4
source share
2 answers

The class path must contain each jar in which you are located.

 java -classpath b.jar;c.jar -jar a.jar //does not work see below 

";" depends on the system for windows ":" for unix.

The jar switch is used to select the jar file whose main class is executing (Main-Class: mobat.Launcher in the manifest file). Command line:

 java -classpath b.jar;c.jar;a.jar mobat.Launcher 

Will produce the same result.

Alternatively, you can add classpath definitions to the manifest file. Your manifest file may contain an attribute.

 Class-Path: lib/b.jar lib/c.jar 

Then

 java -jar a.jar 

will work.

Edit:

I thought that -jar and -cp could be used together. But the java tools documentation is clear:

-jar
When you use this option, the JAR file is the source for all user classes and the other path to the custom class settings are ignored.

Only those versions of the manifest work and everything that exists (classes and classes).

+8
source

You cannot use -cp and -jar together

java -cp myjar.jar;lib/*;. mypackage.MyClass

works on windows and

java -cp myjar.jar:lib/*:. mypackage.MyClass

working on unix

0
source

All Articles