JUL TO SLF4J on TomEE 1.7.2 with maven plugin

时间:2015-10-15 07:00:51

标签: java maven logging slf4j tomee

我想在一个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$3.run(LogManager.java:399)
    at java.util.logging.LogManager$3.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.access$800(LogManager.java:145)
    at java.util.logging.LogManager$2.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类文件存在。

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

谢谢!

1 个答案:

答案 0 :(得分:1)

<li>org.slf4j:slf4j-api:1.7.12</li>
li标签内缺少

b。刚刚用lib

更新