stegzzz
stegzzz

Reputation: 407

absolute versus relative path names in jar manifest

I want to reference a jar file in fixed location for use by multiple executable jars rather than include that jar in each of the executables. I have the following setup which works fine

commons-math3-3.6.1.jar exists in directory testgradle. TestGradle.jar contains the main method and exists in directory testgradle/build/libs

from testgradle/build/libs I run:

java -jar TestGradle.jar

And things work fine. The manifest in TestGradle.jar contains:

Manifest-Version: 1.0
Class-Path: ../../commons-math3-3.6.1.jar
Main-Class: com.spgxyz.test.testg

But I want to address commons-math3-3.6.1.jar with an absolute path so that executable jars such as TestGradle.jar can use it from whichever directory they reside in. However, if I change TestGradle.jar manifest to include the full path:

Manifest-Version: 1.0
Class-Path: C:\Users\Admin\workspace\TestGradle\commons-math3-3.6.1.ja
 r
Main-Class: com.spgxyz.test.testg

Then the command:

java -jar TestGradle.jar

run from testgradle/build/libs produces:

Error: Could not find or load main class com.spgxyz.test.testg
Caused by: java.lang.ClassNotFoundException: com.spgxyz.test.testg

I tried various edits to the manifest to try to cure this such as:

Manifest-Version: 1.0
Class-Path: . C:\Users\Admin\workspace\TestGradle\commons-math3-3.6.1.
 jar
Main-Class: com.spgxyz.test.testg

Manifest-Version: 1.0
Class-Path: TestGradle.jar C:\Users\Admin\workspace\TestGradle\commons
 -math3-3.6.1.jar
Main-Class: com.spgxyz.test.testg

These both produce the same error. If someone could shed some light on what's going on here I'd be very grateful. Running on windows.

Upvotes: 4

Views: 5974

Answers (1)

Roman Puchkovskiy
Roman Puchkovskiy

Reputation: 11865

Class-Path attribute is interpreted as a list of URLs, so, to use an absolute path (represented with a URL here), it should start with schema and use forward slashes.

Try the following:

Class-Path: file:///C:/Users/Admin/workspace/TestGradle/commons-math3-3.6.1.jar

Upvotes: 4

Related Questions