Java.Lang.Noclassdeffounderror: Lorg/Apache/Logging/Log4J/Logger; But the Artifact Exists

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger in generated jar file

When you run it from IDEA dependencies are included by IDEA, you can check the command in Run Tool Window of IDEA.
But when you generate a jar and run it there is no dependencies included in it. To make it work you have to tell Maven to include them, one of the way to do it is to use Apache Maven Assembly Plugin by adding build section to your pom.xml:


Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

According to Spring documentation (as pointed out by Simon), we want to exclude the "spring-boot-starter-logging" module from all libraries, not just from "spring-boot-starter-web".

configurations {
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'

...instead of...

dependencies {
implementation('org.springframework.boot:spring-boot-starter') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'

I myself had the same problem and solved it with this solution.

Related Topics

Leave a reply