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>

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

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

目录
相关文章
|
2月前
|
Java Maven 开发者
"揭秘IDEA的神奇助手:Maven Helper插件,让你轻松驾驭复杂依赖,告别冲突噩梦!"
【8月更文挑战第20天】Maven Helper是一款提升Java开发者工作效率的IDEA插件,它能直观展示项目依赖关系并协助管理。主要功能包括依赖树视图、冲突检测与解决及依赖排除。安装简便,重启IDEA后即用。借助其“Dependencies”面板,开发者可以清晰了解依赖详情,快速定位并解决冲突问题,有效优化项目结构,提升开发效率。
147 0
|
5月前
|
安全 前端开发 Java
安全同学讲Maven重打包的故事
经过去年的Log4j-core的治理工作,我们通过Maven的依赖仲裁机制,在蚂蚁集团静态代码扫描平台-STC 和资产威胁透视-哈勃2款产品的联动合作下,很好的完成了直接依赖和间接依赖场景下的治理工作。但路还很远,新的场景层出不穷,故事还远远没有结束,我们要做的事情还非常多。
145 12
|
5月前
|
缓存 Java Maven
Maven找不到依赖终极解决方案
Maven找不到依赖终极解决方案
538 0
|
Java 测试技术 Maven
Maven 打包跳过测试的 5 种方法,应有尽有,还有谁不会!?
Maven 打包跳过测试的 5 种方法,应有尽有,还有谁不会!?
|
XML 缓存 JavaScript
换掉 Maven,我用它!!!
换掉 Maven,我用它!!!
|
JSON Dubbo Java
Maven:第一章:关于maven依赖死活都下载不了终极解决方案
Maven:第一章:关于maven依赖死活都下载不了终极解决方案
558 0
Maven:第一章:关于maven依赖死活都下载不了终极解决方案
|
缓存 Java Maven
项目根pom导入依赖爆红,死活解决不了
项目根pom导入依赖爆红,死活解决不了
|
JavaScript Java Maven
通过一些常见问题回顾Maven依赖中容易犯错的点(下)
通过一些常见问题回顾Maven依赖中容易犯错的点(下)
通过一些常见问题回顾Maven依赖中容易犯错的点(下)
|
消息中间件 JavaScript Java
通过一些常见问题回顾Maven依赖中容易犯错的点(上)
通过一些常见问题回顾Maven依赖中容易犯错的点(上)
通过一些常见问题回顾Maven依赖中容易犯错的点(上)
|
Java Maven
通过一些常见问题回顾Maven依赖中容易犯错的点(中)
通过一些常见问题回顾Maven依赖中容易犯错的点(中)
通过一些常见问题回顾Maven依赖中容易犯错的点(中)