Maven JarClassLoader:警告:X.jar中的Foo.class被Y.jar隐藏(具有不同的字节码)

时间:2014-03-28 18:07:25

标签: java maven pom.xml javax.mail geronimo

只要我将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>

我开始接收大量的警告信息(当我运行构建的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
)

我的程序运行正常(并发送电子邮件很好),但我不希望所有这些数百个JarClassLoader警告......

任何想法如何恢复和平与安宁安静到我的控制台日志?


更新:感谢下面的Jigar Joshi提示,我发现不受欢迎的geronimo-javamail_1.4_spec-1.7.1.jar来自 org.apache.cxf:cxf-api:jar:2.7.1 :编译,所以我添加了一个排除:

   <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>

并且mvn dependency:tree命令不再将“geronimo”显示为依赖项,但是当我运行新生成的jar(从clean构建时)时,我仍然会收到所有这些警告。

其他建议?


更新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>

1 个答案:

答案 0 :(得分:3)

警告说你有多个jar存在相同的类,所以它可能会在运行时造成麻烦

例如:

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)

我假设您正在寻找mail-1.4.1.jar而不是geronimo-javamail_1.4_spec-1.7.1.jar的课程

你必须排除这个非想要的jar,这样它就不会在classpath中使用它,无论是使用<exclusions>还是<optional>标记,它可能来自其他jar的依赖< / p>

执行mvn dependency:tree以跟踪它的来源和<exclude>


另见