简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM