Java: Which of multiple resources on classpath JVM takes?(Java:类路径 JVM 上的多个资源中的哪一个?)
问题描述
如果我在类路径上有多个同名文件(例如,我有多个 .jar 和 log4j.properties),JVM 遵循什么规则来选择一个?
If I have multiple files of the same name on classpath (e.g. I have multiple .jar with log4j.properties), what are the rules JVM follows to chose one?
推荐答案
使用-classpath选项指定资源(即通常是jar文件)的顺序来指定.类路径上较早"的资源优先于在它们之后指定的资源.这也可以在您的应用程序的清单文件中设置,然后您不需要提供 -classpath 选项.您可能需要查看这些文章,了解如何使用清单文件.
It is specified by the order in which the resources (i.e. usually jar files) are specified using -classpath option. Resources 'earlier' on the classpath take precedence over resources that are specified after them. This can be also set in the manifest file of your application and then you don't need to provide -classpath option. You may want to check these articles on how to work with manifest files.
可以在这里,JAR-class-path Classes部分描述了JAR文件搜索的逻辑.
The exhaustive description of "how classes are found" can be found here, where the section on JAR-class-path Classes describes the logic of JAR-files searching.
这篇关于Java:类路径 JVM 上的多个资源中的哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java:类路径 JVM 上的多个资源中的哪一个?
基础教程推荐
- Java Swing计时器未清除 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
