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

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

一、今天在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>

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

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

目录
相关文章
|
27天前
|
XML Java Maven
【Maven技术专题】「知识盲区」教你如何使用深入分析Maven配置私服仓库的使用指南
【Maven技术专题】「知识盲区」教你如何使用深入分析Maven配置私服仓库的使用指南
37 0
|
2月前
|
缓存 Java Maven
Maven找不到依赖终极解决方案
Maven找不到依赖终极解决方案
175 0
|
4月前
|
XML Java Maven
Maven的入门级——介绍,安装,导入项目,全网最最详细教程!!,包含可能会包的错误的已经指出来了
Maven的入门级——介绍,安装,导入项目,全网最最详细教程!!,包含可能会包的错误的已经指出来了
|
12月前
|
XML 缓存 JavaScript
换掉 Maven,我用它!!!
换掉 Maven,我用它!!!
|
JSON Dubbo Java
Maven:第一章:关于maven依赖死活都下载不了终极解决方案
Maven:第一章:关于maven依赖死活都下载不了终极解决方案
451 0
Maven:第一章:关于maven依赖死活都下载不了终极解决方案
|
消息中间件 JavaScript Java
通过一些常见问题回顾Maven依赖中容易犯错的点(上)
通过一些常见问题回顾Maven依赖中容易犯错的点(上)
通过一些常见问题回顾Maven依赖中容易犯错的点(上)
|
Java Maven
通过一些常见问题回顾Maven依赖中容易犯错的点(中)
通过一些常见问题回顾Maven依赖中容易犯错的点(中)
通过一些常见问题回顾Maven依赖中容易犯错的点(中)
|
JavaScript Java Maven
通过一些常见问题回顾Maven依赖中容易犯错的点(下)
通过一些常见问题回顾Maven依赖中容易犯错的点(下)
通过一些常见问题回顾Maven依赖中容易犯错的点(下)
|
Java Maven
“三招“破idea创建maven项目速度慢问题
“三招“破idea创建maven项目速度慢问题
688 0
“三招“破idea创建maven项目速度慢问题
|
存储 XML Java
不忘初心,牢记使命——SSM始于Maven,终于Maven(关于Maven的大总结)
不忘初心,牢记使命——SSM始于Maven,终于Maven(关于Maven的大总结)
不忘初心,牢记使命——SSM始于Maven,终于Maven(关于Maven的大总结)