Use the Maven tool to resolve jar pack conflicts or duplicate loading issues __log4j

Source: Internet
Author: User
Tags zookeeper log4j

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.