[英]log4J Not Finding Properties file Used by JAR
我们有一个从Windows中的命令提示符运行的JAR,它具有log4J的以下参数:
-Dlog4.properties.file=C:/[folderName]/apps/[appName]/config/log4j.properties
即使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.
我觉得我缺少基本的东西,所以我愿意接受想法...
从简短的介绍到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,问题消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.