[英]Maven JarClassLoader: Warning:Foo.class in X.jar is hidden byY.jar (with different bytecode)
As soon as I added java.mail support to my project: 一旦将java.mail支持添加到我的项目中:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
I started receiving a flood of warning messages like these (when I run the built jar): 我开始收到大量这样的警告消息(运行构建的jar时):
JarClassLoader: Warning: javax/mail/Address.class in lib/mail-1.4.1.jar is hidden by lib/geronimo-javamail_1.4_spec-1.7.1.jar (with different bytecode)
JarClassLoader: Warning: javax/mail/AuthenticationFailedException.class in lib/mail-1.4.1.jar is hidden by lib/geronimo-javamail_1.4_spec-1.7.1.jar (with differ
ent bytecode)
JarClassLoader: Warning: javax/mail/Authenticator.class in lib/mail-1.4.1.jar is hidden by lib/geronimo-javamail_1.4_spec-1.7.1.jar (with different bytecode)
JarClassLoader: Warning: javax/mail/BodyPart.class in lib/mail-1.4.1.jar is hidden by lib/geronimo-javamail_1.4_spec-1.7.1.jar (with different bytecode)
JarClassLoader: Warning: javax/mail/EventQueue.class in lib/mail-1.4.1.jar is hidden by lib/geronimo-javamail_1.4_spec-1.7.1.jar (with different bytecode)
JarClassLoader: Warning: javax/mail/FetchProfile$Item.class in lib/mail-1.4.1.jar is hidden by lib/geronimo-javamail_1.4_spec-1.7.1.jar (with different bytecode
)
My program runs fine (and sends email fine), but I don't want all these hundreds of JarClassLoader warnings... 我的程序运行正常(并可以正常发送电子邮件),但是我不希望所有这数百种JarClassLoader警告...
Any idea how to restore peace & quiet to my console log? 知道如何恢复控制台日志的宁静与安静吗?
Update: Thanks to the tip by Jigar Joshi below, I found that the undesired geronimo-javamail_1.4_spec-1.7.1.jar comes from org.apache.cxf:cxf-api:jar:2.7.1:compile , so I added an exclusion: 更新:感谢下面的Jigar Joshi的技巧,我发现不需要的geronimo-javamail_1.4_spec-1.7.1.jar来自org.apache.cxf:cxf-api:jar:2.7.1:compile ,所以我添加了排除:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<version>2.7.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-javamail_1.4_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
And the mvn dependency:tree
command no longer shows "geronimo" as a dependency, but I am still getting all these warnings when I run the newly resulting jar (built from clean!) 而且
mvn dependency:tree
命令不再将“ geronimo”显示为依赖项,但是当我运行新生成的jar(从clean构建)时,我仍然收到所有这些警告。
Additional suggestions? 还有其他建议吗?
Update 2: This is the dependencies section in my pom.xml : 更新2:这是我pom.xml中的依赖项部分:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.1</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.1</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.6.Final</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<version>2.7.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-javamail_1.4_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
That warning says you have same class present from multiple jar so it could cause trouble at runtime 该警告说您在多个jar中存在同一个类,因此可能在运行时引起麻烦
for example: 例如:
JarClassLoader: Warning: javax/mail/EventQueue.class in lib/mail-1.4.1.jar is hidden by lib/geronimo-javamail_1.4_spec-1.7.1.jar (with different bytecode)
I assume you are looking for that class from mail-1.4.1.jar
and not from geronimo-javamail_1.4_spec-1.7.1.jar
for example 我假设您正在从
mail-1.4.1.jar
而不是从geronimo-javamail_1.4_spec-1.7.1.jar
寻找geronimo-javamail_1.4_spec-1.7.1.jar
。
You would have to exclude this non wanted jar so that it doesn't make itself available in classpath, either by use of <exclusions>
or <optional>
tag, it might be coming from other jar's dependency 您将必须排除此不需要的jar,以使其无法通过使用
<exclusions>
或<optional>
标记在类路径中使用,它可能来自其他jar的依赖项
execute mvn dependency:tree
to track it down from where it is coming and <exclude>
it 执行
mvn dependency:tree
来跟踪它的来临并<exclude>
Also See 另请参阅
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.