JUL TO SLF4J on TomEE 1.7.2 with maven plugin

JUL TO SLF4J on TomEE 1.7.2 with maven plugin

我想在 tomee maven 项目中使用 SLF4J api 和 LOG4J2 impl。结果我在 pom.xml 中添加了 :

<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jul-to-slf4j</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.4</version>
    </dependency>

我这样编辑了 TomEE 的 logging.properties 文件:

handlers = org.slf4j.bridge.SLF4JBridgeHandler

然后我尝试使用此 maven 命令 运行 我的项目:

mvn package tomee:run

不幸的是我遇到了一个例外:

objc[2756]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Handler error
java.lang.ClassNotFoundException: org.slf4j.bridge.SLF4JBridgeHandler
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:560)
    at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:503)
    at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:311)
    at java.util.logging.LogManager.run(LogManager.java:399)
    at java.util.logging.LogManager.run(LogManager.java:396)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.logging.LogManager.readPrimordialConfiguration(LogManager.java:396)
    at java.util.logging.LogManager.access0(LogManager.java:145)
    at java.util.logging.LogManager.run(LogManager.java:345)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.logging.LogManager.ensureLogManagerInitialized(LogManager.java:338)
    at java.util.logging.LogManager.getLogManager(LogManager.java:378)
    at java.util.logging.Logger.demandLogger(Logger.java:448)
    at java.util.logging.Logger.getLogger(Logger.java:502)
    at org.apache.juli.logging.DirectJDKLog.<init>(DirectJDKLog.java:71)
    at org.apache.juli.logging.DirectJDKLog.getInstance(DirectJDKLog.java:196)
    at org.apache.juli.logging.LogFactory.getInstance(LogFactory.java:67)
    at org.apache.juli.logging.LogFactory.getInstance(LogFactory.java:93)
    at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:102)
    at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:59)

我尝试将依赖项添加为 lib :

<plugin>
            <groupId>org.apache.openejb.maven</groupId>
            <artifactId>tomee-maven-plugin</artifactId>
            <configuration>
                <context>ROOT</context>
                <libs>
                    <li>org.slf4j:slf4j-api:1.7.12</li>
                    <lib>org.slf4j:jul-to-slf4j:1.7.12</lib>
                </libs>
            </configuration>
        </plugin>

我可以在 Maven 控制台中看到:

[INFO] Copied 'org.slf4j:slf4j-api:1.7.12' in '/Users/xxx/Work/Git/xxx/target/apache-tomee/lib/slf4j-api-1.7.12.jar
[INFO] Copied 'org.slf4j:jul-to-slf4j:1.7.12' in '/Users/xxx/Work/Git/xxx/target/apache-tomee/lib/jul-to-slf4j-1.7.12.jar

但我遇到了同样的异常:(

查看 jul-to-slf4j-1.7.12.jar 我可以看到 org.slf4j.bridge.SLF4JBridgeHandler class 文件存在。

我不明白为什么tomee找不到它? mac 的 JDK 错误是否可能与此有关? objc[10012]: Class JavaLaunchHelper is implemented in both ... libinstrument.dylib. One of the two will be used. Which one is undefined

谢谢!

<li>org.slf4j:slf4j-api:1.7.12</li>

li 标签内缺少 b。刚刚更新了 lib