unexpected exception: java.lang.NoClassDefFoundError: org/apache/log4j/LogManager

前端 未结 3 2017
遇见更好的自我
遇见更好的自我 2020-12-06 17:52

I\'m developing a GWT application. It\'s using RPC to collect information from an internal system. It does so by using a library jar, lets call it alpha.jar. We are using th

相关标签:
3条回答
  • 2020-12-06 17:54

    org.apache.log4j.LogManager is a class from log4j 1.2 (not log4j2).

    Therefore, one of your web app jars must be referencing it. The culprit should be visible in the stack trace.

    Depending upon your circumstances, you may want to just add a log4j 1.2 jar to the web app as the two versions are completely independent of each other.

    0 讨论(0)
  • 2020-12-06 17:57

    If you have use log4j 2 please do not forget to name your log4j2.xml instead of log4j.xml

    0 讨论(0)
  • 2020-12-06 18:04

    as refered before:

    org.apache.log4j.LogManager is a class from log4j 1.2 (not log4j2).

    this problem meets when you combine use log4j 1.2 and log4j 2.x, maybe. so you have to add bridge api to you project.

    this is a Migrating problem.

    • Log4j – Migrating from Log4j 1.x - Apache Log4j 2

    add those to you pom.xml

            <log4j2.version>2.7</log4j2.version>
            <disruptor.version>3.3.6</disruptor.version>
    
            <!--log4j2 dependencies -->
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
                <version>${log4j2.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
                <version>${log4j2.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-1.2-api</artifactId>
                <version>${log4j2.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-slf4j-impl</artifactId>
                <version>${log4j2.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-jcl</artifactId>
                <version>${log4j2.version}</version>
            </dependency>
            <dependency>
                <groupId>com.lmax</groupId>
                <artifactId>disruptor</artifactId>
                <version>${disruptor.version}</version>
            </dependency>
    

    then, you could use mvn dependency:resolve to see no log4j 1.2

    [INFO] The following files have been resolved:
    [INFO]    org.springframework.data:spring-data-redis:jar:1.7.2.RELEASE:compile
    [INFO]    org.apache.logging.log4j:log4j-api:jar:2.7:compile
    [INFO]    org.apache.logging.log4j:log4j-slf4j-impl:jar:2.7:compile
    [INFO]    com.lmax:disruptor:jar:3.3.6:compile
    [INFO]    org.apache.logging.log4j:log4j-1.2-api:jar:2.7:compile
    [INFO]    javax.mail:mail:jar:1.4.5:compile
    [INFO]    org.springframework:spring-tx:jar:4.3.1.RELEASE:compile
    [INFO]    org.apache.logging.log4j:log4j-core:jar:2.7:compile
    [INFO]    org.apache.logging.log4j:log4j-jcl:jar:2.7:compile
    [INFO]    javax.activation:activation:jar:1.1:compile
    [INFO]    org.springframework:spring-beans:jar:4.3.1.RELEASE:compile
    [INFO]    org.springframework:spring-web:jar:4.3.1.RELEASE:compile
    [INFO]    org.springframework:spring-webmvc:jar:4.3.1.RELEASE:compile
    [INFO]    org.springframework:spring-oxm:jar:4.2.6.RELEASE:compile
    [INFO]    org.springframework:spring-jdbc:jar:4.3.1.RELEASE:compile
    [INFO]    com.alibaba:fastjson:jar:1.2.4:compile
    [INFO]    mysql:mysql-connector-java:jar:5.1.21:compile
    [INFO]    org.apache.tomcat:tomcat-servlet-api:jar:7.0.54:provided
    [INFO]    org.slf4j:slf4j-api:jar:1.7.21:compile
    [INFO]    org.springframework:spring-context-support:jar:4.3.1.RELEASE:compile
    [INFO]    commons-beanutils:commons-beanutils:jar:1.8.3:compile
    [INFO]    org.springframework:spring-context:jar:4.3.1.RELEASE:compile
    [INFO]    org.hamcrest:hamcrest-core:jar:1.3:test
    [INFO]    redis.clients:jedis:jar:2.8.1:compile
    [INFO]    org.springframework:spring-expression:jar:4.3.1.RELEASE:compile
    [INFO]    org.springframework.data:spring-data-commons:jar:1.12.2.RELEASE:compile
    [INFO]    org.springframework.data:spring-data-keyvalue:jar:1.1.2.RELEASE:compile
    [INFO]    junit:junit:jar:4.12:test
    [INFO]    org.springframework:spring-core:jar:4.3.1.RELEASE:compile
    [INFO]    commons-logging:commons-logging:jar:1.2:compile
    [INFO]    org.springframework:spring-aop:jar:4.3.1.RELEASE:compile
    [INFO]    org.apache.commons:commons-pool2:jar:2.4.2:compile
    [INFO]    org.slf4j:jcl-over-slf4j:jar:1.7.21:runtime
    

    refers:

    • Log4j 1.x Adaptor – Log4j 1.2 Bridge - Apache Log4j 1.x Compatibility API

    • Log4j Commons Logging Adaptor – Commons Logging Bridge - Apache Log4j Commons Logging Bridge

    • SLF4J Binding Using Log4j – Log4j 2 SLF4J Binding - Apache Log4j SLF4J Binding
    0 讨论(0)
提交回复
热议问题