将单个文件包含在 Java VM 的 -classpath 参数中是否正确?
目前的做法是在类路径中包含单个文件(JAR 文件除外,例如配置文件或数据文件)。这被认为是正确的吗?为什么或为什么不正确?
更新:
来自http://docs .oracle.com/javase/7/docs/tooldocs/windows/java.html:
-cp 类路径 指定目录、JAR 存档和 ZIP 存档的列表以搜索类文件。类路径条目以分号分隔 (;)。指定 -classpath 或 -cp 会覆盖任何设置 CLASSPATH环境变量。
这个问题也可以解释为询问,上面的目录、JAR 存档和 ZIP 存档的枚举是否包含隐式的“仅此而已”?
更新:
不接受答案,因为在我更改类路径以包含目录而不是特定文件后,程序开始工作。因此,我正在调查是否涉及其他问题,或者指定单个文件是否不起作用(或者至少并不总是起作用)。
更新:
来自http://docs .oracle.com/javase/7/docs/tooldocs/windows/classpath.html:
既不是目录也不是档案(.zip 或 .jar 文件)的类路径条目将被忽略。
Current practice here is to include individual files (other than JAR files, such as configuration files or data files) in the classpath. Is this considered correct and why or why not?
Update:
From http://docs.oracle.com/javase/7/docs/tooldocs/windows/java.html:
-cp classpath
Specify a list of directories, JAR archives, and ZIP archives to search for class files. Class path entries are separated by semicolons
(;). Specifying -classpath or -cp overrides any setting of the
CLASSPATH environment variable.
This question can also be interpreted as asking, does the above enumeration of directories, JAR archives, and ZIP archives contain an implicit "and nothing else"?
Update:
Un-accepting an answer because after I changed my classpath to include a directory rather than specific files, the program began working. So I am investigating whether there was some other issue involved or whether specifying individual files doesn't work (or at least, doesn't always work).
Update:
From http://docs.oracle.com/javase/7/docs/tooldocs/windows/classpath.html:
Classpath entries that are neither directories nor archives (.zip or .jar files) are ignored.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
类路径包含目录或 jar 文件
The classpath contains either directories or jar files
如果您的程序使用 Classloader.getResourceAsStream() (或某种类似的方式)加载这些其他文件,那么将这些文件包含在类路径中是非常有意义的。
这对于与应用程序捆绑在一起的许可证文件来说很常见。
所以,是的,这被认为是正确的——至少从我的角度来看。
If your program loads those other files using
Classloader.getResourceAsStream()
(or some similar way) then it makes perfect sense to include those files in the classpath.This is common e.g. for license files that are bundled with an application.
So yes this is considered correct - at least from my point of view.
来自 http://docs.oracle.com/javase/7/文档/tooldocs/windows/java.html:
来自 http://docs.oracle.com/javase/7/文档/tooldocs/windows/classpath.html:
更远:
From http://docs.oracle.com/javase/7/docs/tooldocs/windows/java.html:
From http://docs.oracle.com/javase/7/docs/tooldocs/windows/classpath.html:
Further: