您的位置:首页 > 其它

解决maven传递依赖中的版本冲突

2016-02-28 11:26 471 查看
搭建项目的出现了jsp页面报了一个很莫名其妙的错误,咋一看好像是将JSP编译成Servlet产生了错误,类不匹配,怀疑可能是JSTL,Servlet和Tomcat版本产生了冲突。在回想下,我并没有改动什么jsp的包,就在之前加入了hdfs的包,于是把hdfs的依赖删了,项目就不报错了,那么问题自然就是出现在我引入hdfs的包有问题了。

引入hdfs的包怎么会跟jsp有关系呢,,难道hdfs的包中也有传递依赖到其他jsp的包,于是借助maven的一个maven-project-info-reports-plugin插件,他可以帮我们看到哪个包的传递依赖产生的冲突。

首先在pom.xml中添加:

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId> maven-project-info-reports-plugin </artifactId>
</plugin>
</plugins>
</reporting>


如果用的是eclipse,那就用run as-build-在Goals那个框框里输入:

project-info-reports:dependencies,如果实在dos环境下,

就mvn project-info-reports:dependencies。然后就会在target的文件夹下,生成一个site文件夹,里边有个dependency.html,进去就能看到详细的依赖的信息。

可以看出所有的依赖关系,果然,hadoop-common包依赖了servlet-api, jasper-runtime等可能与当前环境冲突的jar包,由于这些都是通过依赖关系链产生的关系,所以非常不容易被察觉。

同样,也可以通过mvn自带的工具在项目中命令行操作得到整个依赖的树形结构:

[INFO] cn.edu.cylg.cis.hicloud:hicloudbasic:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework:spring-aop:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-aspects:jar:4.0.4.RELEASE:compile
[INFO] |  \- org.aspectj:aspectjweaver:jar:1.7.4:compile
[INFO] +- org.springframework:spring-beans:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-dao:jar:2.0.8:compile
[INFO] +- org.springframework:spring-expression:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-mock:jar:2.0.8:compile
[INFO] +- org.springframework:spring-orm:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.0.4.RELEASE:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.34:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.0.1:compile
[INFO] +- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.apache.james:apache-mime4j:jar:0.6.1:compile
[INFO] +- asm:asm:jar:3.3.1:compile
[INFO] +- org.apache.axis:axis:jar:1.4:compile
[INFO] +- cglib:cglib-nodep:jar:3.1:compile
[INFO] +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO] +- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] +- commons-discovery:commons-discovery:jar:0.5:compile
[INFO] +- commons-fileupload:commons-fileupload:jar:1.3.1:compile
[INFO] +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] +- commons-io:commons-io:jar:2.4:compile
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- com.alibaba:druid:jar:1.0.9:compile
[INFO] |  +- com.alibaba:jconsole:jar:1.8.0:system
[INFO] |  \- com.alibaba:tools:jar:1.8.0:system
[INFO] +- net.sf.ehcache:ehcache-core:jar:2.6.9:compile
[INFO] +- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] +- org.freemarker:freemarker:jar:2.3.21:compile
[INFO] +- com.google.code.gson:gson:jar:2.3.1:compile
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.4:compile
[INFO] +- org.apache.httpcomponents:httpmime:jar:4.3.6:compile
[INFO] |  \- org.apache.httpcomponents:httpclient:jar:4.3.6:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.4.4:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] +- javax.xml:jaxrpc-api:jar:1.1:compile
[INFO] +- jstl:jstl:jar:1.2:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.9:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.9:compile
[INFO] +- taglibs:standard:jar:1.1.2:compile
[INFO] +- wsdl4j:wsdl4j:jar:1.6.3:compile
[INFO] +- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] +- org.hibernate:hibernate-ehcache:jar:4.3.11.Final:compile
[INFO] +- org.hibernate:hibernate-validator:jar:5.2.2.Final:compile
[INFO] |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  \- com.fasterxml:classmate:jar:1.1.0:compile
[INFO] +- xsqlbuilder:xsqlbuilder:jar:1.0.0:compile
[INFO] +- org.apache.sqoop:sqoop-client:jar:1.99.4:compile
[INFO] |  +- com.google.guava:guava:jar:11.0.2:compile
[INFO] |  +- org.apache.sqoop:sqoop-common:jar:1.99.4:compile
[INFO] |  |  \- com.googlecode.json-simple:json-simple:jar:1.1:compile
[INFO] |  \- com.sun.jersey:jersey-client:jar:1.11:compile
[INFO] +- org.apache.hadoop:hadoop-common:jar:2.6.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-annotations:jar:2.6.0:compile
[INFO] |  |  \- jdk.tools:jdk.tools:jar:1.6:system
[INFO] |  +- commons-cli:commons-cli:jar:1.2:compile
[INFO] |  +- org.apache.commons:commons-math3:jar:3.1.1:compile
[INFO] |  +- xmlenc:xmlenc:jar:0.52:compile
[INFO] |  +- commons-net:commons-net:jar:3.1:compile
[INFO] |  +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] |  +- org.mortbay.jetty:jetty:jar:6.1.26:compile
[INFO] |  +- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
[INFO] |  +- com.sun.jersey:jersey-core:jar:1.9:compile
[INFO] |  +- com.sun.jersey:jersey-json:jar:1.9:compile
[INFO] |  |  +- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO] |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
[INFO] |  |  |  \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] |  |  |     +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  |  |     \- javax.activation:activation:jar:1.1:compile
[INFO] |  |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile
[INFO] |  |  \- org.codehaus.jackson:jackson-xc:jar:1.8.3:compile
[INFO] |  +- com.sun.jersey:jersey-server:jar:1.9:compile
[INFO] |  +- tomcat:jasper-compiler:jar:5.5.23:runtime
[INFO] |  +- net.java.dev.jets3t:jets3t:jar:0.9.0:compile
[INFO] |  |  \- com.jamesmurty.utils:java-xmlbuilder:jar:0.4:compile
[INFO] |  +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] |  |  +- commons-digester:commons-digester:jar:1.8:compile
[INFO] |  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
[INFO] |  +- org.apache.avro:avro:jar:1.7.4:compile
[INFO] |  |  +- com.thoughtworks.paranamer:paranamer:jar:2.3:compile
[INFO] |  |  \- org.xerial.snappy:snappy-java:jar:1.0.4.1:compile
[INFO] |  +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-auth:jar:2.6.0:compile
[INFO] |  |  +- org.apache.directory.server:apacheds-kerberos-codec:jar:2.0.0-M15:compile
[INFO] |  |  |  +- org.apache.directory.server:apacheds-i18n:jar:2.0.0-M15:compile
[INFO] |  |  |  +- org.apache.directory.api:api-asn1-api:jar:1.0.0-M20:compile
[INFO] |  |  |  \- org.apache.directory.api:api-util:jar:1.0.0-M20:compile
[INFO] |  |  \- org.apache.curator:curator-framework:jar:2.6.0:compile
[INFO] |  +- com.jcraft:jsch:jar:0.1.42:compile
[INFO] |  +- org.apache.curator:curator-client:jar:2.6.0:compile
[INFO] |  +- org.apache.curator:curator-recipes:jar:2.6.0:compile
[INFO] |  +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  +- org.htrace:htrace-core:jar:3.0.4:compile
[INFO] |  +- org.apache.zookeeper:zookeeper:jar:3.4.6:compile
[INFO] |  \- org.apache.commons:commons-compress:jar:1.4.1:compile
[INFO] |     \- org.tukaani:xz:jar:1.0:compile
[INFO] +- org.apache.hadoop:hadoop-hdfs:jar:2.6.0:compile
[INFO] |  +- commons-daemon:commons-daemon:jar:1.0.13:compile
[INFO] |  +- javax.servlet.jsp:jsp-api:jar:2.1:compile
[INFO] |  +- tomcat:jasper-runtime:jar:5.5.23:compile
[INFO] |  |  \- commons-el:commons-el:jar:1.0:compile
[INFO] |  +- io.netty:netty:jar:3.6.2.Final:compile
[INFO] |  \- xerces:xercesImpl:jar:2.9.1:compile
[INFO] +- org.apache.hadoop:hadoop-client:jar:2.6.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-mapreduce-client-app:jar:2.6.0:compile
[INFO] |  |  +- org.apache.hadoop:hadoop-mapreduce-client-common:jar:2.6.0:compile
[INFO] |  |  |  +- org.apache.hadoop:hadoop-yarn-client:jar:2.6.0:compile
[INFO] |  |  |  \- org.apache.hadoop:hadoop-yarn-server-common:jar:2.6.0:compile
[INFO] |  |  \- org.apache.hadoop:hadoop-mapreduce-client-shuffle:jar:2.6.0:compile
[INFO] |  |     \- org.fusesource.leveldbjni:leveldbjni-all:jar:1.8:compile
[INFO] |  +- org.apache.hadoop:hadoop-yarn-api:jar:2.6.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-mapreduce-client-core:jar:2.6.0:compile
[INFO] |  |  \- org.apache.hadoop:hadoop-yarn-common:jar:2.6.0:compile
[INFO] |  \- org.apache.hadoop:hadoop-mapreduce-client-jobclient:jar:2.6.0:compile
[INFO] +- axis-ant:axis-ant:jar:1.0:system
[INFO] +- fcexporter:fcexporter:jar:1.0:system
[INFO] +- fcexporthandler:fcexporthandler:jar:1.0:system
[INFO] +- fchelper:fchelper:jar:1.0:system
[INFO] +- fcsampleshelper:fcsampleshelper:jar:1.0:system
[INFO] +- fctl:fctl:jar:1.0:system
[INFO] +- jsonlib:jsonlib:jar:1.0:system
[INFO] +- jackson:jackson:jar:1.0:system
[INFO] +- jpush:jpush:jar:1.0:system
[INFO] +- mail:mail:jar:1.0:system
[INFO] +- ojdbc6:ojdbc6:jar:1.0:system
[INFO] +- pinyin4j:pinyin4j:jar:1.0:system
[INFO] +- poi:poi:jar:1.0:system
[INFO] +- poi-examples:poi-examples:jar:1.0:system
[INFO] +- poi-excelant:poi-excelant:jar:1.0:system
[INFO] +- poi-ooxml:poi-ooxml:jar:1.0:system
[INFO] +- poi-ooxml-schemas:poi-ooxml-schemas:jar:1.0:system
[INFO] +- poi-scratchpad:poi-scratchpad:jar:1.0:system
[INFO] +- QRCode:QRCode:jar:1.0:system
[INFO] +- saaj:saaj:jar:1.0:system
[INFO] +- shiro:shiro:jar:1.0:system
[INFO] +- sun-misc:sun-misc:jar:1.0:system
[INFO] +- ueditor:ueditor:jar:1.0:system
[INFO] +- java_websocket:java_websocket:jar:1.0:system
[INFO] +- weaver-1.6.8:weaver-1.6.8:jar:1.0:system
[INFO] \- junit:junit:jar:3.8.1:test (scope not updated to compile)


于是,通过右键将这些jar包排除(Exclude)出去,最后编辑生成的依赖成为了这样:

<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>${hadoop.version}</version>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
<exclusion>
<artifactId>jasper-compiler</artifactId>
<groupId>tomcat</groupId>
</exclusion>
<exclusion>
<artifactId>jasper-runtime</artifactId>
<groupId>tomcat</groupId>
</exclusion>
<exclusion>
<artifactId>jsp-api</artifactId>
<groupId>javax.servlet.jsp</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>${hadoop.version}</version>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
<exclusion>
<artifactId>jasper-runtime</artifactId>
<groupId>tomcat</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>${hadoop.version}</version>
</dependency>


这里得以解决收到这位仁兄很大帮助,这里感谢他!!

http://brandnewuser.iteye.com/blog/2208969
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: