In the process of using MAVEN to develop a project, you often encounter problems with jar package reloading or jar pack conflicts, but because some jars are loaded automatically because of Maven dependency loading,
Instead of being configured by the developer, especially when the jar bundle that is configured in the POM in the project relies on itself a lot, developers rely on their own experience, sometimes it is hard to find out which jar load caused the load
Unnecessary dependencies on the jar, resulting in conflicts.
Today I just had a chance to share the problem of using the Maven plugin in eclipse to resolve the jar bundle dependency conflict.
The issues that arise in the project are as follows:
caused by:java.lang.NoClassDefFoundError:Could not initialize class Org.apache.log4j.Log4jLoggerFactory
After the search on the internet on the edge of Daniel pointed out:
Log4j-over-slf4j.jar and Slf4j-log4j12.jar will be in the same classpath under the same error.
Workaround:
to exclude Slf4j-log4j12.jar from the associated Jar
However, looking at the Pom file in the MAVEN project, you did not configure the jar's dependencies, guessing that Maven loaded the dependency pack introduced by other jars.
Open the Pom.xml file and view the dependency hierarchy of the jar package in the dependency hierarchy (dependent list).
Enter log4j in the filter bar, the log4j dependency structure appears on the right, and the Pom.xml list of all dependent packages on the left is displayed.
directly on the right, select the SLF4J jar package under Zookeeper, right-click the exclude, and then save Pom.xml. This will not load the SLF4J jar package when the Zookeeper jar package is loaded.
the corresponding dependency files are as follows:
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper< /artifactid>
<version>3.4.6</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</ exclusion>
</exclusions>
</dependency>
This allows you to quickly find the corresponding jar through filter filtering and know his dependencies and quickly resolve the jar pack conflicts in your project.