2

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?

0

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Based on my experiments, it seems that the Class-Path attribute prevails over the CLASSPATH environment variable (when not using -jar), but I'm not sure. Do you happen to know?
-2

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.

1 Comment

Not correct. If you use -jar all other classpaths are ignored.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.