Package conflict
1. When using maven to manage projects, you may encounter package conflicts. For example, when log4j-over-slf4j.jar and slf4j-log4j12.jar, there will be problems when the two packages are run together at the same time.
2. This conflict may be caused by explicit dependencies or implicit dependencies.
Explicit dependencies, you can directly see references to two conflicting packages from the <dependency> of the pom.xml file.
Implicit dependencies, conflicting packages cannot be seen in the <dependency> of pom.xml, but are indirectly introduced by the packages introduced in <dependency>.
solve
First confirm which dependencies have indirectly introduced the package. Use mvn dependency:tree to view the dependency tree of the entire project, where you can see all dependencies, including indirect dependencies.
The results are similar to the following:
[INFO] +- junit:junit:jar:4.12:test[INFO] | /- org.hamcrest:hamcrest-core:jar:1.3:test[INFO] +- org.apache.storm:storm-core:jar:1.0.2:provided[INFO] | +- com.esotericsoftware:kryo:jar:3.0.3:compile[INFO] | | /- com.esotericsoftware:minlog:jar:1.3.0:compile[INFO] | +- org.clojure:clojure:jar:1.7.0:provided[INFO] | +- com.lmax:disruptor:jar:3.3.2:provided[INFO] | +- org.apache.logging.log4j:log4j-api:jar:2.1:provided[INFO] | +- org.apache.logging.log4j:log4j-core:jar:2.1:provided[INFO] | +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.1:provided[INFO] | +- org.slf4j:log4j-over-slf4j:jar:1.6.6:provided[INFO] | +- javax.servlet:servlet-api:jar:2.5:provided[INFO] | /- org.slf4j:slf4j-api:jar:1.7.7:compile[INFO] +- com.aaa.khala:aaa-khala-insight-sdk-transfer-api:jar:1.0.0-SNAPSHOT:compile[INFO] | /- com.aaa.khala:aaa-khala-common:jar:1.0.0-SNAPSHOT:compile[INFO] | +- javax.mail:javax.mail-api:jar:1.5.5:compile[INFO] | +- cglib:cglib:jar:2.2.2:compile[INFO] | +- org.aspectj:aspectjrt:jar:1.7.4:compile[INFO] | +- org.aspectj:aspectjweaver:jar:1.7.4:runtime[INFO] | +- org.javassist:javassist:jar:3.20.0-GA:compile[INFO] | +- log4j:log4j:jar:1.2.17:compile[INFO] | +- org.slf4j:slf4j-log4j12:jar:1.7.7:compile[INFO] | +- dom4j:dom4j:jar:1.6.1:compile[INFO] | +- jaxen:jaxen:jar:1.1.6:compile[INFO] | +- org.apache.commons:commons-compress:jar:1.6:compile[INFO] | +- org.apache.commons:commons-compress:jar:1.6:compile[INFO] | | /- org.tukaani:xz:jar:1.4:compile
If you find the corresponding dependencies of the conflicting package, configure the exclusion in the <dependency> of pom.xml, the package will not be introduced, for example:
<dependency> <groupId>com.aaa.khala</groupId> <artifactId>aaa-khala-insight-sdk-transfer-api</artifactId> <version>1.0.0-SNAPSHOT</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions></dependency>
Thank you for reading, I hope it can help you. Thank you for your support for this site!