【问题标题】:log4J Not Finding Properties file Used by JARlog4J 找不到 JAR 使用的属性文件
【发布时间】:2016-06-01 07:27:00
【问题描述】:

我们有一个 JAR,它在 Windows 中使用以下 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.

我觉得我缺少一些基本的东西,所以我对想法持开放态度......

【问题讨论】:

    标签: java logging log4j


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我已经编辑了答案 - 请立即尝试。
      【解决方案3】:

      试试这个参数:

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

      【讨论】:

      • 您的建议和下面的建议似乎都没有什么不同。我将编辑我的问题以包含我在调试模式下运行 log4J 时收到的消息,以防万一……
      • 您是否将系统属性放在 -jar 标志之前以运行您的应用程序?
      猜你喜欢
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2014-01-29
      • 2011-05-06
      相关资源
      最近更新 更多