简体   繁体   English

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

[英]log4J Not Finding Properties file Used by JAR

We have a JAR that is run from the command prompt in Windows with the following parameter for log4J: 我们有一个从Windows中的命令提示符运行的JAR,它具有log4J的以下参数:

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

Even though the log4j.properties file is indeed in the path above, log4j fails to find it and thus fails to configure properly, and running the command with the parameter -Dlog4j.debug doesn't give me much more information: 即使log4j.properties文件确实在上面的路径中,log4j也找不到它,因此无法正确配置,并且使用参数-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.

I feel like I'm missing somrthing fundamental, so I'm open to ideas... 我觉得我缺少基本的东西,所以我愿意接受想法...

From the short introduction to log4j try using file: as a prefix on the path, only if your properties are not on the classpath. 简短的介绍到log4j ,仅当属性不在类路径上时,才尝试在路径上使用file:作为前缀。 The property is also called log4j.configuration therefore your JVM argument should have following form: 该属性也称为log4j.configuration因此您的JVM参数应采用以下形式:
-Dlog4.configuration=file:/c:/[...]/log4j.properties

试试这个参数:

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

It looks as though my problem was due to a Java version mismatch. 看来我的问题是由于Java版本不匹配所致。 The application in question currently only runs on 1.5, and I built the JAR accordingly. 该应用程序当前仅在1.5上运行,因此我相应地构建了JAR。 But one of its dependencies (ie, another JAR) was built with 1.6. 但是其中一个依赖项(即另一个JAR)是使用1.6构建的。 Built this other JAR with 1.5 and the problem went away. 用1.5构建了另一个JAR,问题消失了。

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

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