【问题标题】:Maven war plugin creates war with multiple versions of same jarMaven 战争插件使用同一个 jar 的多个版本创建战争
【发布时间】:2018-01-12 15:29:07
【问题描述】:

我遇到以下问题。我有一个遗留应用程序,其中 maven-war-plugin 采用以下方式:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webappDirectory>${basedir}/WebRoot</webappDirectory>
        <warSourceDirectory>${basedir}/WebRoot</warSourceDirectory>
    </configuration>
    <version>3.2.0</version>
</plugin>

具体情况是项目的源码树的src层有一个特殊的文件夹WebRoot

然后,当我更改了某些依赖项的版本并开始构建时 mvn clean package 最后我得到了一个带有WEB-INF/lib 的project.war,其中充满了新旧工件的两个版本。这会在 servlet 容器中的战争开始时造成麻烦,因为不清楚哪些 jar 是由类加载器加载的,并且某些 jar 存在不同的不兼容问题。

编辑: mvn dependency:tree -Dverbose

[INFO] yyy:sometool:war:0.1.15-SNAPSHOT
[INFO] +- org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.0.1:compile
[INFO] |  +- ch.qos.logback:logback-core:jar:1.0.1:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
[INFO] +- org.slf4j:log4j-over-slf4j:jar:1.6.4:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.6.4:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
[INFO] +- javax.mail:mail:jar:1.4.1:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- javax.servlet:jstl:jar:1.2:provided
[INFO] +- javax.servlet:servlet-api:jar:2.4:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.1:provided
[INFO] +- org.codehaus.woodstox:wstx-lgpl:jar:3.2.7:compile
[INFO] |  \- stax:stax-api:jar:1.0.1:compile
[INFO] +- org.apache.struts:struts2-core:jar:2.1.8:compile
[INFO] |  +- com.opensymphony:xwork-core:jar:2.1.6:compile
[INFO] |  |  +- org.springframework:spring-test:jar:2.5.6:compile
[INFO] |  |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.0.4)
[INFO] |  |  |  \- (junit:junit:jar:3.8.1:compile - omitted for conflict with 3.8.2)
[INFO] |  |  \- (ognl:ognl:jar:2.7.3:compile - omitted for duplicate)
[INFO] |  +- org.freemarker:freemarker:jar:2.3.15:compile
[INFO] |  +- ognl:ognl:jar:2.7.3:compile
[INFO] |  +- commons-fileupload:commons-fileupload:jar:1.2.1:compile
[INFO] |  \- commons-io:commons-io:jar:1.3.2:compile
[INFO] +- org.apache.struts:struts2-convention-plugin:jar:2.1.8:compile
[INFO] |  \- (org.apache.struts:struts2-core:jar:2.1.8:compile - omitted for duplicate)
[INFO] +- org.apache.struts:struts2-dojo-plugin:jar:2.1.8:compile
[INFO] |  \- (org.apache.struts:struts2-core:jar:2.1.8:compile - omitted for duplicate)
[INFO] +- struts2plugin:struts2pluginLogin:jar:0.0.6:compile
[INFO] |  +- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
[INFO] |  \- (ch.qos.logback:logback-classic:jar:1.0.0:compile - omitted for conflict with 1.0.1)
[INFO] +- org.apache.struts:struts2-json-plugin:jar:2.1.8:compile
[INFO] |  +- org.apache.struts:struts2-junit-plugin:jar:2.1.8:compile
[INFO] |  |  +- (junit:junit:jar:3.8.2:compile - omitted for conflict with 4.8.1)
[INFO] |  |  \- (org.apache.struts:struts2-core:jar:2.1.8:compile - omitted for duplicate)
[INFO] |  \- (org.apache.struts:struts2-core:jar:2.1.8:compile - omitted for duplicate)
[INFO] +- org.hibernate:hibernate-annotations:jar:3.3.1.GA:compile
[INFO] |  +- (org.hibernate:hibernate:jar:3.2.6.ga:compile - omitted for conflict with 3.2.5.ga)
[INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.0.0.ga:compile
[INFO] |  |  \- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for duplicate)
[INFO] |  +- org.hibernate:ejb3-persistence:jar:1.0.1.GA:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.3.2.GA:compile
[INFO] |  +- (org.hibernate:hibernate:jar:3.2.6.ga:compile - omitted for duplicate)
[INFO] |  +- (org.hibernate:hibernate-annotations:jar:3.3.1.GA:compile - omitted for duplicate)
[INFO] |  +- (org.hibernate:hibernate-commons-annotations:jar:3.0.0.ga:compile - omitted for duplicate)
[INFO] |  +- (org.hibernate:ejb3-persistence:jar:1.0.1.GA:compile - omitted for duplicate)
[INFO] |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for duplicate)
[INFO] |  \- javassist:javassist:jar:3.4.GA:compile
[INFO] +- org.hibernate:hibernate-validator:jar:3.0.0.ga:compile
[INFO] +- org.hibernate:hibernate:jar:3.2.5.ga:compile
[INFO] |  +- net.sf.ehcache:ehcache:jar:1.2.3:compile
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for duplicate)
[INFO] |  |  \- (commons-collections:commons-collections:jar:2.1:compile - omitted for conflict with 2.1.1)
[INFO] |  +- (javax.transaction:jta:jar:1.0.1B:compile - omitted for conflict with 1.1)
[INFO] |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for duplicate)
[INFO] |  +- asm:asm-attrs:jar:1.5.3:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  +- cglib:cglib:jar:2.1_3:compile
[INFO] |  |  \- (asm:asm:jar:1.5.3:compile - omitted for duplicate)
[INFO] |  +- asm:asm:jar:1.5.3:compile
[INFO] |  \- (commons-collections:commons-collections:jar:2.1.1:compile - omitted for conflict with 3.2.1)
[INFO] +- mysql:mysql-connector-java:jar:5.1.13:compile
[INFO] +- c3p0:c3p0:jar:0.9.1.2:compile
[INFO] +- xerces:xercesImpl:jar:2.9.1:compile
[INFO] |  \- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for conflict with 1.0.b2)
[INFO] +- displaytag:displaytag:jar:1.2:compile
[INFO] |  +- (commons-collections:commons-collections:jar:3.1:compile - omitted for conflict with 2.1.1)
[INFO] |  +- commons-lang:commons-lang:jar:2.3:compile
[INFO] |  +- com.lowagie:itext:jar:1.3:compile
[INFO] |  \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO] +- javax.transaction:jta:jar:1.1:compile
[INFO] +- javax.persistence:persistence-api:jar:1.0:compile
[INFO] +- org.quartz-scheduler:quartz:jar:2.1.5:compile
[INFO] |  +- (c3p0:c3p0:jar:0.9.1.1:compile - omitted for conflict with 0.9.1.2)
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for conflict with 1.6.4)
[INFO] +- org.springframework:spring-context:jar:5.0.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:5.0.2.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-beans:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-beans:jar:5.0.2.RELEASE:compile
[INFO] |  |  \- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-core:jar:5.0.2.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.0.2.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:5.0.2.RELEASE:compile
[INFO] |     \- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-webmvc:jar:5.0.2.RELEASE:compile
[INFO] |  +- (org.springframework:spring-aop:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-beans:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-context:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-expression:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  \- org.springframework:spring-web:jar:5.0.2.RELEASE:compile
[INFO] |     +- (org.springframework:spring-beans:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |     \- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] +- net.unto.twitter:java-twitter:jar:0.9-SNAPSHOT:compile
[INFO] |  +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for duplicate)
[INFO] |  |  \- commons-codec:commons-codec:jar:1.2:compile
[INFO] |  +- (commons-io:commons-io:jar:1.4:compile - omitted for conflict with 1.3.2)
[INFO] |  +- com.google.protobuf:protobuf-java:jar:2.2.0:compile
[INFO] |  +- (commons-lang:commons-lang:jar:2.4:compile - omitted for conflict with 2.3)
[INFO] |  +- net.sf.json-lib:json-lib:jar:jdk15:2.2.3:compile
[INFO] |  |  +- (commons-beanutils:commons-beanutils:jar:1.7.0:compile - omitted for duplicate)
[INFO] |  |  +- (commons-collections:commons-collections:jar:3.2:compile - omitted for conflict with 3.2.1)
[INFO] |  |  +- (commons-lang:commons-lang:jar:2.4:compile - omitted for conflict with 2.3)
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.0.4)
[INFO] |  |  \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] |  |     \- (commons-lang:commons-lang:jar:2.3:compile - omitted for duplicate)
[INFO] |  +- (joda-time:joda-time:jar:1.6:compile - omitted for conflict with 2.9.9)
[INFO] |  \- com.google.collections:google-collections:jar:0.9:compile
[INFO] +- junit:junit:jar:4.8.1:test (scope not updated to compile)
[INFO] +- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- joda-time:joda-time:jar:2.9.9:compile
[INFO] +- com.google.guava:guava:jar:19.0:compile
[INFO] +- utils.networking:httpclient:jar:0.1.4:compile
[INFO] |  +- (junit:junit:jar:4.10:compile - omitted for conflict with 4.8.1)
[INFO] |  +- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
[INFO] |  +- (org.slf4j:log4j-over-slf4j:jar:1.6.4:compile - omitted for duplicate)
[INFO] |  +- (org.slf4j:jcl-over-slf4j:jar:1.6.4:compile - omitted for duplicate)
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.1.3:compile
[INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.1.4:compile
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.0.4)
[INFO] |  |  \- (commons-codec:commons-codec:jar:1.4:compile - omitted for conflict with 1.2)
[INFO] |  +- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  +- (org.springframework:spring-context:jar:3.1.1.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  +- org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile
[INFO] |  |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  +- (org.springframework:spring-expression:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  \- org.springframework.security:spring-security-crypto:jar:3.1.0.RELEASE:compile
[INFO] |  |     \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  +- org.springframework.security:spring-security-web:jar:3.1.0.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:3.0.6.RELEASE:compile
[INFO] |  |  |  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-web:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-expression:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- org.springframework:spring-jdbc:jar:3.0.6.RELEASE:compile
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-tx:jar:3.0.6.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  \- org.springframework.security:spring-security-config:jar:3.1.0.RELEASE:compile
[INFO] |     +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |     +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |     +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |     +- (org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
[INFO] |     \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.9.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.3:compile
[INFO] |  +- (com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile - omitted for conflict with 2.9.3)
[INFO] |  \- (com.fasterxml.jackson.core:jackson-core:jar:2.9.3:compile - omitted for duplicate)
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.3:compile
[INFO] \- org.mockito:mockito-core:jar:1.9.0:compile
[INFO]    +- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO]    \- org.objenesis:objenesis:jar:1.0:compile

【问题讨论】:

  • 您能否将mvn dependency:tree -Dverbose 的输出添加到您的问题中。这将有助于故障排除过程
  • 几乎没有同一个工件的多个版本。我认为您有具有相同“artifactId”的不同工件,但它们的“groupId”应该不同。 "dependency:tree" 将有助于找到此类情况。
  • @SergeBogatyrev 太简单了,不过加了。

标签: java maven maven-war-plugin


【解决方案1】:

我找到了解决方案。问题出在这个插件配置上:

<configuration>
    <webappDirectory>${basedir}/WebRoot</webappDirectory>
    <warSourceDirectory>${basedir}/WebRoot</warSourceDirectory>
</configuration>

webappDirectory顾名思义就是maven放爆战的地方。所以在mvn clean package 之后,${basedir}/WebRoot 下有一个 lib 文件夹,里面装满了 pom.xml 中的所有依赖库。另一方面,此文件夹用于打包成战争。因此,每次我更新某个依赖项的版本并启动 mvn clean package 时,都会将新版本的依赖项放入 ${basedir}/WebRoot/lib 而不删除以前的版本。在下一个mvn clean package 之后,它就将整个lib 文件夹打包到了战争中。

解决方案是,不要为warSourceDirectorywebappDirectory 使用同一个文件夹。将webappDirectory 指向&lt;webappDirectory&gt;${project.build.directory}/XYZ&lt;/webappDirectory&gt; 的某处

【讨论】:

    猜你喜欢
    • 2012-03-29
    • 1970-01-01
    • 2015-09-19
    • 1970-01-01
    • 1970-01-01
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多