java manifest classpath vs. -classpath

丶灬走出姿态 提交于 2019-12-12 18:01:27

问题


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?


回答1:


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.




回答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.



来源:https://stackoverflow.com/questions/10233490/java-manifest-classpath-vs-classpath

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!