ed_is_my_name
ed_is_my_name

Reputation: 631

java manifest classpath vs. -classpath

I'm trying to figure out an odd problem I have with an executable jar file: xyz.jar has a classpath in the manifest file / and depends on abc.jar library.

Unfortunately, the manifest classpath in xyz.jar is incorrect. To save from disaster, I'm updating the execution commands to use: java -classpath path/abc.jar:etc instead of java -jar

The problem is that xyz.jar malfuntions unless abc.jar is NOT on the classpath. When abc.jar is removed the program executes correctly, and no exceptions are thrown. Why? xyz.jar must be picking up abc.jar from somewhere else. xyz.jar calls methods in abc.jar.

-classpath should override any $CLASSPATH setting. Is it possible that java still looks at the manifest classpath even when using -classpath?

Upvotes: 2

Views: 4611

Answers (2)

user207421
user207421

Reputation: 310979

If you specify -jar, only the class-path in the manifest is used. All others are ignored. If you need to respecify the classpath, don't use -jar.

Upvotes: 7

Highland Mark
Highland Mark

Reputation: 1010

It is my belief that the Class-Path attribute of a jar manifest file is used to declare the dependencies of classes within that jar, and so is independent of the main classpath. While it is true that using -cp with the java command replaces the ClassPath environment variable, it should have no affect on the individual Class-Path of each jar.

Upvotes: -2

Related Questions