我想使用Maven-shade-plugin创建超级jar。但是,当我调用mvn package
命令时,Maven报告有一些重叠的类。我附加了所有有问题的重叠,其中一些是由于库(Log4J)的旧版本和新版本引起的,但其中一些似乎具有相同的类 - 例如javax.mail和mailapi / smtp / imap等等。
在这种情况下最好做什么?是否有一些关键如何确定哪些重叠是安全的,忽略哪一个需要正确?
- mailapi-1.4.3.jar, javax.mail-1.5.0.jar define 166 overlappping classes
- spring-2.5.6.SEC03.jar, spring-tx-3.1.4.RELEASE.jar define 176 overlappping classes:
- spring-beans-3.1.4.RELEASE.jar, spring-2.5.6.SEC03.jar define 283 overlappping classes:
- slf4j-log4j12-1.7.5.jar, slf4j-impl-2.0-beta2.jar define 3 overlappping classes:
- spring-2.5.6.SEC03.jar, spring-context-support-3.1.4.RELEASE.jar define 55 overlappping classes:
- aopalliance-1.0.jar, spring-2.5.6.SEC03.jar define 9 overlappping classes:
- imap-1.5.0.jar, javax.mail-1.5.0.jar define 87 overlappping classes:
- commons-logging-api-1.1.jar, commons-logging-1.1.3.jar define 19 overlappping classes:
- spring-2.5.6.SEC03.jar, spring-core-3.1.4.RELEASE.jar define 161 overlappping classes:
- spring-2.5.6.SEC03.jar, spring-context-3.1.4.RELEASE.jar define 326 overlappping classes:
- log4j12-api-2.0-beta3.jar, log4j-1.2.17.jar define 23 overlappping classes:
- spring-aop-3.1.4.RELEASE.jar, spring-2.5.6.SEC03.jar define 237 overlappping classes:
- spring-jdbc-3.1.4.RELEASE.jar, spring-2.5.6.SEC03.jar define 239 overlappping classes:
- quartz-1.8.6.jar, quartz-jobs-2.2.1.jar define 15 overlappping classes:
- smtp-1.5.0.jar, javax.mail-1.5.0.jar define 17 overlappping classes:
- spring-asm-3.1.4.RELEASE.jar, spring-2.5.6.SEC03.jar define 31 overlappping classes:
编辑:此应用程序“A”使用另一个Java应用程序作为Maven依赖项 - 我将此应用程序称为“B”。这个B应用程序使用javax.mail ver 1.5.1。该库也使用第一个应用程序。但是当我调用mvn package命令时,Maven会注意到javax.mail-api-1.5.1.jar, javax.mail-1.5.1.jar define 135 overlappping classes
。
这是问题,如果是,如何解决或者我可以忽略它?
答案 0 :(得分:6)
要做的第一件事就是尽可能多地删除重叠类的明显原因。例如:
您不太可能需要在阴影jar中保留类的冲突版本。如果你这样做,那么shade插件也允许重新定位类,如http://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html
所述答案 1 :(得分:4)
I found the maven dependency tree plugin very useful to find out from where is the nested dependency coming from , and then add an exclusion for it.
plot \
"ikpapache.dat" using :1 with linespoints axes x1y1 title "ap rr", \
"ikphaproxy.dat" using :1 with linespoints axes x1y1 title "ha rr", \
"ikphaproxy.dat" using :2 with lines axes x1y1 title "ha cr", \
"ikpapache.dat" using :2 with lines axes x1y1 title "ap minrr", \
"ikphaproxy.dat" using :3 with lines axes x1y1 title "ha minrr", \
"ikpapache.dat" using :3 with lines axes x1y1 title "ap avrr", \
"ikphaproxy.dat" using :4 with lines axes x1y1 title "ha avrr", \
"ikpapache.dat" using :4 with lines axes x1y1 title "ap maxrr", \
"ikphaproxy.dat" using :5 with lines axes x1y1 title "ha maxrr", \
"ikphaproxy.dat" using :6 with lines axes x1y1 title "ha stddevrr", \
"ikpapache.dat" using :($5*200) with linespoints axes x1y1 title "ap rt*200", \
"ikphaproxy.dat" using :($7*200) with linespoints axes x1y1 title "ha rt*200", \
"ikphaproxy.dat" using :8 with lines axes x1y1 title "ha ni", \
"ikpapache.dat" using :($6*100) with lines axes x1y1 title "ap Errs*100", \
"ikphaproxy.dat" using :($9*100) with lines axes x1y1 title "ha Errs*100"
The aopalliance jar is being referenced from spring-context-support which indicates that we could possibly exclude it.
答案 2 :(得分:1)
此问题重复this one,您可以在其中找到更多示例。
但是如果你确定你没有重叠的依赖关系(就像我有的那样),clean
项目可以提供帮助。见this answer for more details