【问题标题】:The WAR in my EAR doesn't load log4j2 properly but the JAR does我 EAR 中的 WAR 没有正确加载 log4j2,但 JAR 可以
【发布时间】:2015-05-05 07:08:15
【问题描述】:

我有这个 EAR 文件。它应该包含在 WildFly 8.2.0.Final 应用服务器中。

- lib
  - log4j-api-2.1.jar
  - log4j-core-2.1.jar
- META-INF
  - application.xml
  - jboss-app.xml
  - log4j2.xml
  - MANIFEST.MF
- my-ejb.jar
- my-web.war (skinny war)
  - META-INF
    - MANIFEST.MF
  - WEB-INF
    - classes
      - ...
    - lib (empty since skinny war)
  - index.html

当我第一次从 my-web.war 开始记录时,我不断收到此消息:2015-03-04 11:04:22,806 ERROR [stderr] (default task-23) ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...,并且没有消息添加到我的日志文件中。

但是,当我从 my-ejb.jar 开始记录时,我一点问题都没有,随后从 my-web.war 进行的记录也可以正常工作。

如何在我的 EAR 文件中正确使用/配置 log4j2,这样我就不必关心我的 ejb 文件是否被首先调用?

文件,按要求:

my-ejb.jar/META-INF/MANIFEST.MF:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: Olivier
Class-Path: lib/log4j-api-2.1.jar lib/guava-18.0.jar lib/log4j-core-2.
 1.jar lib/log4j-web-2.1.jar
Created-By: Apache Maven 3.2.3
Build-Jdk: 1.8.0_25

my-web.war/META-INF/MANIFEST.MF

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: Olivier
Class-Path: lib/log4j-api-2.1.jar lib/guava-18.0.jar lib/log4j-core-2.
 1.jar lib/log4j-web-2.1.jar
Created-By: Apache Maven 3.2.3
Build-Jdk: 1.8.0_25

【问题讨论】:

  • 注意,我也试过添加 log4j-web-2.1.jar。
  • 您是否尝试过从您的 WAR 清单中删除 Class-Path?它可能正在尝试查看WEB-INF/lib
  • 您的清单类路径条目既多余又不正确。 A JAR format file (such as a .jar file, .war file, or .rar file) may reference a .jar file or directory by naming the referenced .jar file or directory in a Class-Path header in the referencing JAR file’s Manifest file. The referenced .jar file or directory is named **using a URL relative to the URL of the referencing JAR file.** EAR/lib 目录中的 jar 文件应该可以在没有清单类路径条目的情况下使用

标签: java wildfly ear log4j2


【解决方案1】:

log4j2.xml 文件必须在类路径中才能被找到。

试着把它放在这里:

my-web.war
   WEB-INF
      classes
          log4j2.xml

【讨论】:

  • 我们可以把这个文件放在wildfly 10的什么地方,以便全局配置日志记录?
【解决方案2】:

my-ejb.jar MANIFEST.MF 是否包含 log4j jar 的相对类路径?如果您想使用自己的 log4j 配置,请将文件 log4j2.xml 放在耳朵的根目录下,并将 jboss-app.xml 放在耳朵的 META-INF 文件夹中,内容如下:

<jboss-app>
<loader-repository>
org.myapp:loader=MyClassLoader
<loader-repository-config>
  java2ParentDelegation=false
</loader-repository-config>
</loader-repository>
</jboss-app>

【讨论】:

  • 感谢您的回答。事实上,my-ejb.jar 中的 MANIFEST.MF 确实包含具有相对路径的类路径。我将 log4j2.xml 移动到耳朵的根目录,并调整了 jboss-app.xml 以包含您编写的内容,将 MyClassLoader 调整为 my-app.ear,这是我的 EAR 文件的名称。但是,在所有这些更改之后,问题仍然存在。
  • 控制台日志修改后有变化吗?可以展示一下吗?
  • 我当然可以展示它,但它根本没有改变:2015-03-04 12:04:26,988 ERROR [stderr] (default task-41) ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
  • 你能从 my-ejb.jar 和 my-web.war 显示 MANIFEST.MF 吗?
  • 这个答案提供了适合 JBossAS 5 和 6 的 jboss-app.xml 内容。在 WildFly 和 JBossAS 7.x 中将被忽略
猜你喜欢
  • 1970-01-01
  • 2012-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-02
  • 1970-01-01
  • 2013-02-27
相关资源
最近更新 更多