简体   繁体   English

Java清单类路径与-classpath

[英]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. 我试图找出一个可执行jar文件存在一个奇怪的问题:xyz.jar在清单文件/中具有类路径,并且依赖于abc.jar库。

Unfortunately, the manifest classpath in xyz.jar is incorrect. 不幸的是,xyz.jar中的清单类路径不正确。 To save from disaster, I'm updating the execution commands to use: java -classpath path/abc.jar:etc instead of java -jar 为了免于灾难,我正在更新执行命令以使用:java -classpath path / abc.jar:etc而不是java -jar

The problem is that xyz.jar malfuntions unless abc.jar is NOT on the classpath. 问题是,除非abc.jar不在类路径上,否则xyz.jar会出现故障。 When abc.jar is removed the program executes correctly, and no exceptions are thrown. 删除abc.jar后,程序将正确执行,并且不会引发任何异常。 Why? 为什么? xyz.jar must be picking up abc.jar from somewhere else. xyz.jar必须是从其他地方拾取的abc.jar。 xyz.jar calls methods in abc.jar. xyz.jar调用abc.jar中的方法。

-classpath should override any $CLASSPATH setting. -classpath应该覆盖任何$ CLASSPATH设置。 Is it possible that java still looks at the manifest classpath even when using -classpath? 即使使用-classpath时,java是否仍会查看清单类路径?

If you specify -jar, only the class-path in the manifest is used. 如果指定-jar,则仅使用清单中的类路径。 All others are ignored. 所有其他都将被忽略。 If you need to respecify the classpath, don't use -jar. 如果需要重新指定类路径,请不要使用-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. 我相信jar清单文件的Class-Path属性用于声明该jar中的类的依赖关系,因此它与主类路径无关。 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. 的确,在Java命令中使用-cp可以替换ClassPath环境变量,但是它对每个jar的单独Class-Path都没有影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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