简体   繁体   中英

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:

-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: 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. The property is also called log4j.configuration therefore your JVM argument should have following form:
-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. The application in question currently only runs on 1.5, and I built the JAR accordingly. But one of its dependencies (ie, another JAR) was built with 1.6. Built this other JAR with 1.5 and the problem went away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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