关闭

Maven dependency 包冲突解决方案

5169人阅读 评论(0) 收藏 举报
分类:

在项目中加入依赖包后运行过程中出现包冲突问题。解决方案:

1. 在cmd环境下,输入如下命令:mvn dependency:tree,根据jar包的依赖树,通过依赖树找到冲突包的不同版本。如下所示:

发现 hbase 依赖包 

org.slf4j:slf4j-api:jar:1.4.3
和storm 依赖包
 org.slf4j:slf4j-log4j12:jar

这两个包在项目中是有冲突的



[INFO] +- org.apache.hbase:hbase:jar:0.94.6:compile
[INFO] |  +- com.yammer.metrics:metrics-core:jar:2.1.2:compile
[INFO] |  +- commons-cli:commons-cli:jar:1.2:compile
[INFO] |  +- org.mortbay.jetty:jsp-2.1:jar:6.1.14:compile
[INFO] |  +- org.mortbay.jetty:jsp-api-2.1:jar:6.1.14:compile
[INFO] |  +- org.mortbay.jetty:servlet-api-2.5:jar:6.1.14:compile
[INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile
[INFO] |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.8.8:compile
[INFO] |  +- org.codehaus.jackson:jackson-xc:jar:1.8.8:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.4.3:compile
[INFO] |  +- tomcat:jasper-compiler:jar:5.5.23:compile


[INFO] +- storm:storm:jar:0.8.2:provided
[INFO] |  +- org.clojure:clojure:jar:1.4.0:provided
[INFO] |  +- commons-io:commons-io:jar:1.4:compile
[INFO] |  +- org.apache.commons:commons-exec:jar:1.1:provided
[INFO] |  +- storm:libthrift7:jar:0.7.0:provided
[INFO] |  |  \- javax.servlet:servlet-api:jar:2.5:provided
[INFO] |  +- clj-time:clj-time:jar:0.4.1:provided
[INFO] |  |  \- joda-time:joda-time:jar:2.0:provided
[INFO] |  +- log4j:log4j:jar:1.2.16:compile
[INFO] |  +- com.netflix.curator:curator-framework:jar:1.0.1:provided
[INFO] |  |  \- com.netflix.curator:curator-client:jar:1.0.1:provided
[INFO] |  +- backtype:jzmq:jar:2.1.0:provided
[INFO] |  +- com.googlecode.json-simple:json-simple:jar:1.1:provided
[INFO] |  +- compojure:compojure:jar:1.1.3:provided
[INFO] |  |  +- org.clojure:core.incubator:jar:0.1.0:provided
[INFO] |  |  +- org.clojure:tools.macro:jar:0.1.0:provided
[INFO] |  |  +- clout:clout:jar:1.0.1:provided
[INFO] |  |  \- ring:ring-core:jar:1.1.5:provided
[INFO] |  |     \- commons-fileupload:commons-fileupload:jar:1.2.1:provided
[INFO] |  +- hiccup:hiccup:jar:0.3.6:provided
[INFO] |  +- ring:ring-jetty-adapter:jar:0.3.11:provided
[INFO] |  |  \- ring:ring-servlet:jar:0.3.11:provided
[INFO] |  +- org.clojure:tools.logging:jar:0.2.3:provided
[INFO] |  +- org.clojure:math.numeric-tower:jar:0.0.1:provided
[INFO] |  +- org.slf4j:slf4j-log4j12:jar:1.5.8:compile


2.选定一个版本的包留下,在要去掉的依赖中 exclusion掉冲突jar


<dependency>
			<groupId>storm</groupId>
			<artifactId>storm</artifactId>
			<version>0.8.2</version>
			<!-- keep storm out of the jar-with-dependencies -->
			<scope>provided</scope>
			<exclusions>
				<exclusion>
					<groupId>org.slf4j</groupId>
					<artifactId>slf4j-log4j12</artifactId>
				</exclusion>
			</exclusions>
		</dependency>



另外在Maven中添加依赖包时,不知道怎么写 dependency的groupid和artifactid时,可在 http://mavenrepository.com  中收索依赖包的dependency的写法。





0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:290953次
    • 积分:4324
    • 等级:
    • 排名:第7275名
    • 原创:127篇
    • 转载:161篇
    • 译文:0篇
    • 评论:21条
    文章分类
    最新评论