简体   繁体   English

在Java 7中使用log4j时找不到log4j.properties

[英]Cannot find log4j.properties when using log4j with java 7

我已经构建了一个可执行jar并使用log4j。首先我使用Java6对其进行了构建,并且运行良好。但是当我将JDK更新到1.7版并再次构建项目时,似乎找不到log4j.properties文件,因为我找不到日志文件,并且控制台中的日志格式也是错误的。

Have you extracted your .JAR file to ensure that "log4j.properties" exists in the root folder? 您是否已提取.JAR文件以确保根文件夹中存在“ log4j.properties”? Are you sure that it is named correctly (it is named "log4j.perperties" in your question). 您确定它的名称正确吗(在您的问题中它的名称为“ log4j.perperties”)。

Troubleshooting suggestions: 故障排除建议:

  1. Run app with "-Dlog4j.debug" flag and observe log4j output 使用“ -Dlog4j.debug”标志运行应用程序并观察log4j输出
  2. Run project without "-jar" to avoid jar packaging issues (eg "java -cp ./xxx.jar com.pkg.AppClass") 运行不带“ -jar”的项目以避免jar打包问题(例如“ java -cp ./xxx.jar com.pkg.AppClass”)
  3. Examine encoding of the log4j.properties file 检查log4j.properties文件的编码
  4. Attempt manual initialization of log4j within your application, first with an external file then with the internal classpath file 尝试在应用程序中手动初始化log4j,首先使用外部文件,然后使用内部类路径文件

I do not see any obvious JDK7 & log4j conflicts with a few minutes of googling, so it doesn't look like a "known JDK7 issue" to me. 几分钟的搜索后,我看不到任何明显的JDK7和log4j冲突,因此对我来说,它看起来像不是“已知的JDK7问题”。

I had a similar problem and the logging never came even though the entries were correct. 我有一个类似的问题,即使输入正确,日志记录也从未出现。 Later I discovered that one of the jar files (jxls-reader-0.9.6.jar) had a file log4j.xml and that was getting loaded first and used as log4j logging property file and hence we did not receive the logs. 后来我发现其中一个jar文件(jxls-reader-0.9.6.jar)具有一个log4j.xml文件,该文件首先被加载并用作log4j日志记录属性文件,因此我们没有收到日志。 I've removed the log4j.xml from the jar and it worked perfectly fine. 我已经从jar中删除了log4j.xml,它工作得很好。

You may have similar problem, hope it may be similar solution. 您可能有类似的问题,希望它可能是类似的解决方案。

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

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