1.查看maven依赖树
命令:mvn dependency:tree
在项目目录下执行mvn dependency:tree,可以比较直观看到jar包的依赖关系
E:\develop\web\project\travel>mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< com.hzh:travel >---------------------------
[INFO] Building travel 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ travel ---
[INFO] com.hzh:travel:war:1.0-SNAPSHOT
[INFO] +- mysql:mysql-connector-java:jar:5.1.30:runtime
[INFO] +- org.mybatis:mybatis:jar:3.5.1:compile
[INFO] +- org.projectlombok:lombok:jar:1.16.20:compile
[INFO] +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO] | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | \- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.9.9:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.9.9:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.9:compile
[INFO] | +- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.9.9:compile
[INFO] | +- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] | \- com.fasterxml.woodstox:woodstox-core:jar:5.1.0:compile
[INFO] +- redis.clients:jedis:jar:2.9.0:compile
[INFO] | \- org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.322 s
[INFO] Finished at: 2020-12-15T22:23:23+08:00
[INFO] ------------------------------------------------------------------------
2.用exclusion排除重复依赖的jar包
因为我的项目用到阿里云服务jar包,可能在其他地方也用到了jaxb-api和gson包就报错了,报错如下:
15-Dec-2020 22:34:40.169 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.startup.ContextConfig.processAnnotationsJar Unable to process Jar entry [module-info.class] from Jar [file:/E:/develop/web/project/travel/target/travel-1.0-SNAPSHOT/WEB-INF/lib/jaxb-api-2.3.1.jar] for annotations
15-Dec-2020 22:34:40.279 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.startup.ContextConfig.processAnnotationsJar Unable to process Jar entry [module-info.class] from Jar [file:/E:/develop/web/project/travel/target/travel-1.0-SNAPSHOT/WEB-INF/lib/gson-2.8.6.jar] for annotations
通过依赖树找到对应的jar包,排除就不报错了
<!-- 阿里云短信包 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.3</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
</exclusions>
</dependency>