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

I am developing a GWT application. It uses RPC to collect information from the internal system. He does this using the jar library, lets call it alpha.jar. We use this jar in many applications, so it works great, and btw built it using ANT, outside of the eclipse.

Some classes in the alpha.jar LOG4J2 links, as well as many other external jars, so when we run the application, we pass the class path to all of these and everything works fine . Please note that this is not a simple beginner problem. Alpha.jar works as it should, including calls to Log4J.

Problem:

In Eclipse, I have this GWT application project, as well as the Alpha.jar project (with source code, of course). The server side should initialize alpha objects and communicate with the alpha system.

When this is done in GWT, adding a link to the build path to the Alpha project, my GWT application works fine.

When instead of linking to the project, I include (in war / WEB-INF / lib) the alpha.jar file and start the application, I get an error in the header when the first instance of the class from alpha.jar.

There are no particularities in how alpha.jar is created, so basically it should be the same as the project in eclipse, right?

Please note the following:

*) Alphabetically dependent banks are also at war / WEB -INF / lib. log4j2-core, log4j-api, as well as many others (e.g. Apache)

*) If I delete alpha.jar (and the code that calls it), and instead just add code called LOG4J2, this code also works great!

Why am I getting this strange error while using JAR ?? Pay attention also to NoClassDefFoundError, it is not more widespread exception ClassNotFoundException. Pls see what are the reasons and what are the differences between NoClassDefFoundError and ClassNotFoundException?

If you need more information, let me know.

+8
source share
3 answers

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

Therefore, one of your web application banners must link to it. The culprit should be visible in the stack trace.

Depending on your circumstances, you can simply add the log4j 1.2 log file to the web application, since the two versions are completely independent of each other.

+12
source

If you use log4j 2, do not forget to specify your log4 j2 .xml instead of log4j.xml

0
source

as mentioned earlier:

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

this problem occurs when you combine using log4j 1.2 and log4j 2.x, perhaps. so you must add an API bridge to your project.

this is a Migrating problem.

add them 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 can use mvn dependency:resolve decide not to see 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 

applies:

0
source

Source: https://habr.com/ru/post/976667/


All Articles