我想使用 Maven-shade-plugin 来创建 uber-jar.但是当我调用 mvn package
命令时,Maven 报告说有一些重叠的类.我附上了所有有问题的重叠,其中一些是由于库(Log4J)的旧版本和新版本引起的,但其中一些似乎具有相同的类 - 例如javax.mail 和 mailapi/smtp/imap 等等.
I would like to use Maven-shade-plugin to create uber-jar. But when I call mvn package
command Maven reports that there are some overlapping classes. I am attaching all problematic overlapps, some of them are caused because older and new verion of a library (Log4J), but some of them seems to have the same classes - e.g. javax.mail and mailapi/smtp/imap et cetera.
在这种情况下最好做什么?是否有一些关键如何决定哪些重叠可以安全忽略哪些需要正确?
What is the best to do in this situation? Is there some key how to decide which overlapping is safe to ignore a which needs to be correct?
- 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 版本 1.5.1.这个库也使用了第一个应用程序.但是当我调用 mvn package 命令时,Maven 注意到 javax.mail-api-1.5.1.jar, javax.mail-1.5.1.jar 定义了 135 个重叠类
.
this application "A" uses as a Maven dependency my another Java application - I'll call this app "B". This B application uses javax.mail ver 1.5.1. This library uses the first application too. But when I call mvn package command, Maven notices that javax.mail-api-1.5.1.jar, javax.mail-1.5.1.jar define 135 overlappping classes
.
是这个问题吗?如果是,如何解决,或者我可以忽略它吗?
Is this problem and if so, how to solve it or can I ignore it?
首先要做的是尽可能多地消除重叠类的明显原因.例如:
The first thing to do is remove as many of the obvious causes of overlapping classes as you can. For instance:
您不太可能需要在阴影 jar 中保留冲突的类版本.如果你这样做了,shade 插件还允许重定位类,如 http://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html
It's unlikely that you will need to retain conflicting versions of the classes in the shaded jar. If you do, the shade plugin also allows the relocation of classes, as described at http://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html
这篇关于Maven-shade-plugin、uber-jar 和重叠类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!