gpt4 book ai didi

java.class.path 不带 Manifest.mf Class-Path 属性

转载 作者:搜寻专家 更新时间:2023-10-31 20:21:44 26 4
gpt4 key购买 nike

我正在尝试获取我的应用程序类路径。

我有一个 jar(名为 application.jar),它的 Manifest.mf 中还有其他 jar 文件,例如 Class-Path: a.jar b.jar.

为什么当我使用 System.getProperty("java.class.path") 我的 jars a.jarb.jar 是没有列出?

最佳答案

这可能与 java.class.path 是从类路径环境变量($CLASSPATH >-类路径)。使用 -jar 选项会忽略这些。

根据 java -jar 文档,当使用该 jar 选项运行应用程序时,仅考虑 list Class-Path 并忽略其他设置。来自 http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html :

-jar

Execute a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. In order for this option to work, the manifest of the JAR file must contain a line of the form Main-Class: classname. Here, classname identifies the class having the public static void main(String[] args) method that serves as your application's starting point. See the Jar tool reference page and the Jar trail of the Java Tutorial for information about working with Jar files and Jar-file manifests.

When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

关于java.class.path 不带 Manifest.mf Class-Path 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13918450/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com