您现在的位置是:首页 > 文章详情

Mavenjar包冲突的问题解决(亲测有效、实力证明)

日期:2018-05-09点击:661

一、今天在Pom中添加了一个依赖,导致Jar包冲突。
在启动项目的时候,会包jar包冲突的问题。下面以SpringBoot项目为例。
我在Pom.xml文件中添加了一个依赖:

 <dependency> <groupId>org.ethereum</groupId> <artifactId>ethereumj-core</artifactId> <version>1.6.3-RELEASE</version> </dependency>

二、在启动项目的时候就会报一个错误

Connected to the target VM, address: '127.0.0.1:57577', transport: 'socket' SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/Users/wangdong/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.7/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/Users/wangdong/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] The Class-Path manifest attribute in /Users/wangdong/.m2/repository/com/sun/xml/bind/jaxb-core/2.3.0/jaxb-core-2.3.0.jar referenced one or more files that do not exist: file:/Users/wangdong/.m2/repository/com/sun/xml/bind/jaxb-core/2.3.0/jaxb-api.jar The Class-Path manifest attribute in /Users/wangdong/.m2/repository/com/sun/xml/bind/jaxb-impl/2.3.0/jaxb-impl-2.3.0.jar referenced one or more files that do not exist: file:/Users/wangdong/.m2/repository/com/sun/xml/bind/jaxb-impl/2.3.0/jaxb-core.jar Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.apache.logging.slf4j.Log4jLoggerFactory loaded from file:/Users/wangdong/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.7/log4j-slf4j-impl-2.7.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.apache.logging.slf4j.Log4jLoggerFactory at org.springframework.util.Assert.instanceCheckFailed(Assert.java:389) at org.springframework.util.Assert.isInstanceOf(Assert.java:327) at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:274) at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:98) at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:230) at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:209) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122) at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69) at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48) at org.springframework.boot.SpringApplication.run(SpringApplication.java:292) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) at com.gws.GwsWebApplication.main(GwsWebApplication.java:19) ... 5 more Disconnected from the target VM, address: '127.0.0.1:57577', transport: 'socket' Process finished with exit code 0

三、仔细看一下这里面的报错
关于日志的两个冲突了,我自己用的是log4j,结果还有一个slf4j

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/Users/wangdong/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.7/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/Users/wangdong/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]

四、定位一下冲突的这个slf4j在哪里。
通过下面这个找:

/Users/wangdong/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar

这里写图片描述

五、下面看看红线框部分的jar包是不是刚刚引入的
把刚刚引入Maven项注释掉,重新编译导下包。
这里写图片描述

六、发现第四部的那两个jar包消失了,那么就说明是刚刚添加的依赖产生了jar包冲突的问题了。

七、那么现在就开始来排除依赖
这里写图片描述

八、这个一定要放到对应的依赖里面
groupId和artifactId一定要根据IDEA的提示写正确。

 <exclusions> <exclusion> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </exclusion> </exclusions>

九、写完后就会发现,冲突的包不见了,就解决啦
这里写图片描述

最后再启动项目,就会成功了。

原文链接:https://yq.aliyun.com/articles/614511
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章