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:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>package.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
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
Java - Replace New Line Character by \N
Regex to Replace Everything After a Specific Symbol - Java
How to Get Spring Boot to Automatically Create Database Schema
How to Download a File from S3 Using Provided Url
Disable Quick Settings Tile in Android
Java.Lang.Classcastexception: [Ljava.Lang.Object; Cannot Be Cast to Classname
Setonclicklistener() on a Null Object Reference Error
Shifting Characters Within a String
How to Use If-Else Logic in Java 8 Stream Foreach
Error: Incompatible Types: Int[][] Cannot Be Converted to Int
How to Read File from Relative Path in Java Project? Java.Io.File Cannot Find the Path Specified
In Java: How to Zip File from Byte[] Array
Check and Open Downloaded File in Selenium
Splitting Data Inside Quotes and Comma Using Regex
Eclipse: the Resource Is Not on the Build Path of a Java Project
How to Send List of Long to Rest Controller Spring Boot
Eclipse Console Not Showing Output
How to Force a Method to Throw an Exception in Junit Testing