log4J 未找到 JAR 使用的属性文件

log4J Not Finding Properties file Used by JAR

我们有一个 JAR,它是 运行 来自 Windows 中的命令提示符,具有以下用于 log4J 的参数:

-Dlog4.properties.file=C:/[folderName]/apps/[appName]/config/log4j.properties

即使log4j.properties文件确实在上面的路径中,log4j也找不到它,因此无法正确配置,运行ning带有参数 -Dlog4j.debug 的命令没有提供更多信息:

log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$Ap pClassLoader@92e78c. log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@92e78c class loader. log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource(). log4j: Trying to find [log4j.properties] using context classloader sun.misc.Laun cher$AppClassLoader@92e78c. log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@ 92e78c class loader. log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource(). log4j: Could not find resource: [null]. log4j:WARN No appenders could be found for logger (com.xxx.yyy.appName.Main). log4j:WARN Please initialize the log4j system properly.

我觉得我缺少一些基本的东西,所以我愿意接受想法...

来自short introduction to log4j 尝试使用 file: 作为路径的前缀,前提是您的属性不在类路径中。 属性 也称为 log4j.configuration 因此您的 JVM 参数应具有以下形式:
-Dlog4.configuration=file:/c:/[...]/log4j.properties

试试这个参数:

-Dlog4j.configuration=file:///C:/[folderName]/apps/[appName]/config/log4j.properties

看来我的问题是由于 Java 版本不匹配造成的。有问题的应用程序目前仅在 1.5 上运行,我相应地构建了 JAR。但是它的一个依赖项(即另一个 JAR)是用 1.6 构建的。用 1.5 重建另一个 JAR,问题消失了...