jar包冲突时怎么办

因为项目中会依赖许多jar包,免不得就会有冲突,那怎么解决呢?

使用

mvn dependency:tree

可以看到各个包的依赖关系

[INFO] |  +- commons-cli:commons-cli:jar:1.4:compile
[INFO] |  +- net.sourceforge.cpdetector:cpdetector:jar:1.0.7:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  +- net.sourceforge.jchardet:jchardet:jar:1.0:compile
[INFO] |  |  \- net.sourceforge.jargs:jargs:jar:1.0:compile
[INFO] |  |     \- junit:junit:jar:4.13:compile
[INFO] |  |        \- org.hamcrest:hamcrest-core:jar:2.2:compile
[INFO] |  +- org.odata4j:odata4j-core:jar:0.8.0:compile
[INFO] |  |  \- org.core4j:core4j:jar:0.5:compile
[INFO] |  +- org.apache.poi:poi-ooxml:jar:3.15:compile
[INFO] |  |  +- org.apache.poi:poi:jar:3.15:compile
[INFO] |  |  +- org.apache.poi:poi-ooxml-schemas:jar:3.15:compile
[INFO] |  |  |  \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO] |  |  |     \- stax:stax-api:jar:1.0.1:compile
[INFO] |  |  \- com.github.virtuald:curvesapi:jar:1.04:compile
[INFO] |  +- commons-io:commons-io:jar:2.6:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.11.0:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.11.0:compile
[INFO] |  +- org.apache.commons:commons-csv:jar:1.5:compile
[INFO] |  +- org.pacesys:openstack4j-core:jar:3.1.0:compile
[INFO] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.11.0:compile
[INFO] |  |  \- com.github.fge:json-patch:jar:1.9:compile
[INFO] |  |     \- com.github.fge:jackson-coreutils:jar:1.6:compile
[INFO] |  |        \- com.github.fge:msg-simple:jar:1.1:compile
[INFO] |  |           \- com.github.fge:btf:jar:1.2:compile
[INFO] |  +- org.pacesys.openstack4j.connectors:openstack4j-httpclient:jar:3.1.0:compile
[INFO] |  +- com.github.oshi:oshi-core:jar:3.4.4:compile
[INFO] |  |  +- net.java.dev.jna:jna-platform:jar:4.5.0:compile
[INFO] |  |  |  \- net.java.dev.jna:jna:jar:4.5.0:compile
[INFO] |  |  \- org.threeten:threetenbp:jar:1.3.6:compile
[INFO] |  +- joda-time:joda-time:jar:2.9.9:compile
[INFO] |  +- com.ecwid.consul:consul-api:jar:1.3.0:compile
[INFO] |  |  \- com.google.code.gson:gson:jar:2.8.6:compile
[INFO] |  +- com.toastcoders:yavijava:jar:6.0.03:compile
[INFO] |  |  +- org.apache.directory.studio:org.dom4j.dom4j:jar:1.6.1:compile
[INFO] |  |  \- log4j:log4j:jar:1.2.17:compile
[INFO] |  +- org.apache.commons:commons-pool2:jar:2.8.0:compile
[INFO] |  +- org.apache.axis:axis:jar:1.4:compile
[INFO] |  +- commons-discovery:commons-discovery:jar:0.2:compile
[INFO] |  +- org.apache.axis:axis-jaxrpc:jar:1.4:compile
[INFO] |  +- org.apache.axis:axis-saaj:jar:1.4:compile
[INFO] |  \- wsdl4j:wsdl4j:jar:1.6.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web-services:jar:2.3.0.RELEASE:compile
[INFO] |  +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.5.2:compile
[INFO] |  |  +- jakarta.xml.soap:jakarta.xml.soap-api:jar:1.4.2:compile
[INFO] |  |  +- org.jvnet.staxex:stax-ex:jar:1.8.3:compile
[INFO] |  |  \- com.sun.activation:jakarta.activation:jar:1.2.2:runtime
[INFO] |  +- jakarta.xml.ws:jakarta.xml.ws-api:jar:2.3.3:compile
[INFO] |  |  \- jakarta.jws:jakarta.jws-api:jar:2.1.0:runtime

找到冲突的包是属于那个依赖产生的,然后pom里使用exclusion标签,排除即可

比如排除spring-boot-starter-logging的依赖:

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
            <version>${spring.boot.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

 

posted @ 2020-06-17 09:32  纵码万水千山  阅读(707)  评论(0编辑  收藏  举报