maven项目引入新依赖问题


title: maven项目引入新依赖问题 tags:

  • Maven categories: 工作日志 date: 2017-05-25 18:18:55

前一篇描述过关于版本号没有写明确,写了release的产生的问题

slf4j 更新版本导致无日志输出

描述一下最近系统中出现的问题。

某一天开发环境突然出现了这种邮件

而正常如下

特别奇怪,为啥出现了主题不见了,内容好似乱码。

用浅薄的mail知识猜测大概是这个被当成附件发送了吧。

那么首先检查发送邮件的配置没有发生变化。其次发现了pom文件出现了变化,大概猜测问题出现在此。

小伙伴在引入新的构件的情况下比如

    <dependency>
        <groupId>org.apache.axis2groupId>
        <artifactId>axis2-adbartifactId>
        <version>1.4version>
    dependency>
复制代码

那么怀疑是否出现了maven仲裁导致之前依赖的某个jar版本发生了变化导致出现了此问题呢?

因此将两次生成的依赖

新的依赖

    activation-1.1.jar                              commons-pool2-2.4.2.jar                 jboss-logging-3.2.1.Final.jar  shiro-core-1.3.0.jar
    annogen-0.1.0.jar                               core-3.2.1.jar                          jedis-2.7.3.jar                shiro-ehcache-1.3.0.jar
    annotations-2.0.1.jar                           countUp.js-1.7.0.jar                    jgroups-3.6.6.Final.jar        shiro-quartz-1.3.0.jar
    ant-1.7.0.jar                                   data-biz-model-1.0.23.jar               jline-0.9.94.jar               shiro-redis-2.4.2.1-RELEASE.jar
    ant-launcher-1.7.0.jar                          data-biz-rmi-1.0.23.jar                 joda-time-2.9.3.jar            shiro-spring-1.3.0.jar
    aopalliance-1.0.jar                             data-biz-vo-1.0.23.jar                  jpinyin-1.1.8.jar              shiro-web-1.3.0.jar
    aspectjweaver-1.8.9.jar                         data-utility-1.0.23.jar                 jquery-raty-2.5.2.jar          slf4j-api-1.7.25.jar
    axiom-api-1.2.7.jar                             dom4j-1.6.1.jar                         json-20090211.jar              spring-aop-3.2.8.RELEASE.jar
    axiom-dom-1.2.7.jar                             dozer-5.2.0.jar                         json-lib-2.2.2-jdk15.jar       spring-beans-3.2.8.RELEASE.jar
    axiom-impl-1.2.7.jar                            dubbo-2.5.3.jar                         jsp-api-2.2.jar                spring-context-3.2.8.RELEASE.jar
    axis2-adb-1.4.jar                               ECharts-2.2.0.2.jar                     jstl-1.2.jar                   spring-context-support-3.2.8.RELEASE.jar
    axis2-kernel-1.4.jar                            ehcache-2.10.1.jar                      kryo-shaded-3.0.0.jar          spring-core-3.2.8.RELEASE.jar
    backport-util-concurrent-3.1.jar                ehcache-core-2.5.3.jar                  log4j-over-slf4j-1.7.7.jar     spring-data-redis-1.6.2.RELEASE.jar
    bcprov-jdk15-1.45.jar                           ezmorph-1.0.4.jar                       logback-access-1.1.7.jar       spring-expression-3.2.8.RELEASE.jar
    biz-mapper-1.0-SNAPSHOT.jar                     fastjson-1.2.24.jar                     logback-classic-1.1.7.jar      spring-jdbc-3.2.8.RELEASE.jar
    biz-model-1.0-SNAPSHOT.jar                      fst-2.42.jar                            logback-core-1.1.7.jar         spring-security-core-4.2.1.RELEASE.jar
    biz-rmi-1.0-SNAPSHOT.jar                        geronimo-activation_1.1_spec-1.0.1.jar  logback-ext-spring-0.1.4.jar   spring-tx-3.2.8.RELEASE.jar
    biz-rmi-impl-1.0-SNAPSHOT.jar                   geronimo-javamail_1.4_spec-1.2.jar      mail-1.4.4.jar                 spring-web-3.2.8.RELEASE.jar
    biz-schedule-1.0-SNAPSHOT.jar                   geronimo-jms_1.1_spec-1.1.jar           minlog-1.3.0.jar               spring-webmvc-3.2.8.RELEASE.jar
    biz-service-1.0-SNAPSHOT.jar                    geronimo-stax-api_1.0_spec-1.0.1.jar    mybatis-3.3.0.jar              stax-api-1.0.1.jar
    biz-service-impl-1.0-SNAPSHOT.jar               guava-18.0.jar                          mybatis-spring-1.2.3.jar       utility-1.0-SNAPSHOT.jar
    biz-vo-1.0-SNAPSHOT.jar                         hibernate-validator-5.2.4.Final.jar     neethi-2.0.4.jar               validation-api-1.1.0.Final.jar
    carzoneAgent-1.0.2.jar                          httpclient-4.4.jar                      netty-3.2.5.Final.jar          woden-api-1.0M8.jar
    carzone-erp-api-supplychain-1.0.10-RELEASE.jar  httpcore-4.4.jar                        netty-3.7.0.Final.jar          woden-impl-dom-1.0M8.jar
    carzone-erp-core-1.0.10-RELEASE.jar             httpcore-nio-4.0-beta1.jar              objenesis-2.1.jar              wsdl4j-1.6.2.jar
    carzone-platform-exception-1.1.RELEASE.jar      j2cache-core-1.4.0.jar                  ognl-3.0.11.jar                wstx-asl-3.2.4.jar
    carzone-platform-validate-2.1.RELEASE.jar       j2cache-shiro-1.0.2.jar                 okhttp-3.2.0.jar               xalan-2.7.0.jar
    Chart.js-2.1.3.jar                              j2cache-spring-1.0.1.jar                okio-1.6.0.jar                 xercesImpl-2.8.1.jar
    classmate-1.1.0.jar                             jackson-annotations-2.6.1.jar           optimist-1.2.0.jar             xml-apis-1.3.04.jar
    commons-beanutils-1.8.3.jar                     jackson-core-2.6.1.jar                  pinyin4j-2.5.0.jar             xmlbeans-2.6.0.jar
    commons-codec-1.9.jar                           jackson-core-asl-1.9.2.jar              poi-3.12.jar                   xmlParserAPIs-2.6.0.jar
    commons-collections-3.2.1.jar                   jackson-databind-2.6.1.jar              poi-ooxml-3.12.jar             XmlSchema-1.4.2.jar
    commons-fileupload-1.2.1.jar                    jackson-mapper-asl-1.9.2.jar            poi-ooxml-schemas-3.12.jar     zkclient-0.1.jar
    commons-httpclient-3.1.jar                      java-sdk-3.13.jar                       quartz-1.6.1.jar               zookeeper-3.4.6.jar
    commons-io-2.4.jar                              javassist-3.11.0.GA.jar                 quartz-all-1.6.1.jar
    commons-lang-2.6.jar                            javassist-3.19.0-GA.jar                 rapid-core-4.0.jar
    commons-logging-1.1.1.jar                       jaxen-1.1.1.jar                         reflections-0.9.10.jar
复制代码

老的依赖

    activation-1.1.jar                             countUp.js-1.7.0.jar                 jgroups-3.6.6.Final.jar       quartz-1.6.1.jar
    annotations-2.0.1.jar                          data-biz-model-1.0.23.jar            jline-0.9.94.jar              quartz-all-1.6.1.jar
    aopalliance-1.0.jar                            data-biz-rmi-1.0.23.jar              joda-time-2.9.3.jar           rapid-core-4.0.jar
    aspectjweaver-1.8.9.jar                        data-biz-vo-1.0.23.jar               jpinyin-1.1.8.jar             reflections-0.9.10.jar
    bcprov-jdk15-1.45.jar                          data-utility-1.0.23.jar              jquery-raty-2.5.2.jar         shiro-core-1.3.0.jar
    biz-mapper-1.0-SNAPSHOT.jar                    dozer-5.2.0.jar                      json-20090211.jar             shiro-ehcache-1.3.0.jar
    biz-model-1.0-SNAPSHOT.jar                     dubbo-2.5.3.jar                      json-lib-2.2.2-jdk15.jar      shiro-quartz-1.3.0.jar
    biz-rmi-1.0-SNAPSHOT.jar                       ECharts-2.2.0.2.jar                  jsp-api-2.2.jar               shiro-redis-2.4.2.1-RELEASE.jar
    biz-rmi-impl-1.0-SNAPSHOT.jar                  ehcache-2.10.1.jar                   jstl-1.2.jar                  shiro-spring-1.3.0.jar
    biz-schedule-1.0-SNAPSHOT.jar                  ehcache-core-2.5.3.jar               kryo-shaded-3.0.0.jar         shiro-web-1.3.0.jar
    biz-service-1.0-SNAPSHOT.jar                   ezmorph-1.0.4.jar                    log4j-1.2.16.jar              slf4j-api-1.7.25.jar
    biz-service-impl-1.0-SNAPSHOT.jar              fastjson-1.2.24.jar                  logback-access-1.1.7.jar      spring-aop-3.2.8.RELEASE.jar
    biz-vo-1.0-SNAPSHOT.jar                        fst-2.42.jar                         logback-classic-1.1.7.jar     spring-beans-3.2.8.RELEASE.jar
    carzoneAgent-1.0.2.jar                         guava-18.0.jar                       logback-core-1.1.7.jar        spring-context-3.2.8.RELEASE.jar
    carzone-erp-api-supplychain-1.0.9-RELEASE.jar  hibernate-validator-5.2.4.Final.jar  logback-ext-spring-0.1.4.jar  spring-context-support-3.2.8.RELEASE.jar
    carzone-erp-core-1.0.9-RELEASE.jar             httpclient-4.4.jar                   mail-1.4.4.jar                spring-core-3.2.8.RELEASE.jar
    carzone-platform-exception-1.1.RELEASE.jar     httpcore-4.4.jar                     minlog-1.3.0.jar              spring-data-redis-1.6.2.RELEASE.jar
    carzone-platform-validate-2.1.RELEASE.jar      j2cache-core-1.4.0.jar               mybatis-3.3.0.jar             spring-expression-3.2.8.RELEASE.jar
    Chart.js-2.1.3.jar                             j2cache-shiro-1.0.2.jar              mybatis-spring-1.2.3.jar      spring-jdbc-3.2.8.RELEASE.jar
    classmate-1.1.0.jar                            j2cache-spring-1.0.1.jar             netty-3.2.5.Final.jar         spring-security-core-4.2.1.RELEASE.jar
    commons-beanutils-1.8.3.jar                    jackson-annotations-2.6.1.jar        netty-3.7.0.Final.jar         spring-tx-3.2.8.RELEASE.jar
    commons-codec-1.9.jar                          jackson-core-2.6.1.jar               objenesis-2.1.jar             spring-web-3.2.8.RELEASE.jar
    commons-collections-3.2.1.jar                  jackson-core-asl-1.9.2.jar           ognl-3.0.11.jar               spring-webmvc-3.2.8.RELEASE.jar
    commons-fileupload-1.2.1.jar                   jackson-databind-2.6.1.jar           okhttp-3.2.0.jar              stax-api-1.0.1.jar
    commons-httpclient-3.1.jar                     jackson-mapper-asl-1.9.2.jar         okio-1.6.0.jar                utility-1.0-SNAPSHOT.jar
    commons-io-2.4.jar                             java-sdk-3.13.jar                    optimist-1.2.0.jar            validation-api-1.1.0.Final.jar
    commons-lang-2.6.jar                           javassist-3.11.0.GA.jar              pinyin4j-2.5.0.jar            xmlbeans-2.6.0.jar
    commons-logging-1.1.1.jar                      javassist-3.19.0-GA.jar              poi-3.12.jar                  zkclient-0.1.jar
    commons-pool2-2.4.2.jar                        jboss-logging-3.2.1.Final.jar        poi-ooxml-3.12.jar            zookeeper-3.4.6.jar
    core-3.2.1.jar                                 jedis-2.7.3.jar                      poi-ooxml-schemas-3.12.jar
复制代码

比较后发现有个

geronimo-javamail_1.4_spec-1.2.jar的组件比较奇怪(问为什么?哈哈 经验呗)
复制代码

通过查看依赖

证实该jar是被

axis2-adb构建引入
复制代码

发现该jar包含

javax.mail.internet.MimeMultipart

 
复制代码

而java-mail同样包含

疑问如下:

  1. 那么原先使用的是java-mail为啥这两个jar没有被maven的仲裁(理解成法官就好了)裁判呢?(maven只会针对GA相同的构建进行依赖仲裁,而且并不是选择版本最高的构建是选择路径最短的构建进行应用)
  2. 为啥java加载的是geronimo-javamail的而不是mail呢,这个涉及到tomcat classloader的加载机制

当应用需要到某个类时,则会按照下面的顺序进行类加载

  1 使用bootstrap引导类加载器加载

  2 使用system系统类加载器加载

  3 使用应用类加载器在WEB-INF/classes中加载

  4 使用应用类加载器在WEB-INF/lib中加载

  5 使用common类加载器在CATALINA_HOME/lib中加载

那么同样lib下面的是以排序为准(不同机器不同系统排序可能会不一样)

因此在引入新的构建的情况下需要摸清楚依赖是否必须,是否部分需要排除(最常见的就是servlet的jar,可以通过scope配置)

因此总结知识点如下:

  1. maven仲裁
  2. 构件scope
  3. tomcat类加载机制

在引入构件的时候需要注意一下是否影响到了原来组件版本(比如仲裁后版本变化),需要对比一下前后jar版本等等。

修改如下

好习惯值得拥有:尽量定义 dependencyManagement 通过该元素管理依赖事半功倍

你可能感兴趣的:(maven项目引入新依赖问题)