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>

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

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

目录
相关文章
|
9月前
|
数据采集 存储 安全
一文带你讲透数据仓库分层!
在数据处理中,常遇到数据混乱、指标不一致、开发排期长等问题,根源往往在于数据分层设计不合理。本文详解数据仓库分层(ODS、DWD、DWS、DM、APP等),阐述其在数据清洗、整合、管理及应用中的关键作用,帮助提升数据质量、减少重复开发、增强系统扩展性,从而高效支撑业务决策。
一文带你讲透数据仓库分层!
|
JavaScript
vue里怎么使用pdf.js实现pdf文件的预览功能
vue里怎么使用pdf.js实现pdf文件的预览功能
1939 0
vue里怎么使用pdf.js实现pdf文件的预览功能
|
7月前
|
存储 安全 Apache
StarRocks 4.0:基于 Apache Iceberg 的 Catalog 中心化访问控制
StarRocks 4.0 已正式发布!这一版本带来了多项关键升级。接下来,我们将以每周一篇的节奏,逐一解析 4.0 的核心新特性。 在多引擎协同访问同一数据湖的场景下,如何实现安全、统一且可审计的权限管理,是 Lakehouse 架构演进中的一项关键挑战。StarRocks 4.0 联合 Apache Iceberg,借助 REST Catalog 的统一治理能力与 JWT 身份认证、临时凭证机制(Vended Credential),为多引擎湖仓架构提供了一种全新的安全访问方式。
|
7月前
|
架构师 关系型数据库 MySQL
【Java架构师体系课 | MySQL篇】③ Explain执行计划详解
Explain用于分析SQL执行计划,通过模拟优化器行为揭示查询性能瓶颈。它展示索引使用、扫描行数等信息,帮助优化查询语句,提升数据库效率。
622 6
【Java架构师体系课 | MySQL篇】③ Explain执行计划详解
|
7月前
|
架构师 IDE Java
【Java架构师】Maven中lombok那点事
SpringBoot项目中Lombok需在maven-compiler-plugin中配置`annotationProcessorPaths`,确保编译期生成getter/setter等方法;而`excludes`则在打包时排除Lombok依赖,减小体积,因运行时已无需该库。
746 1
|
6月前
|
XML 自然语言处理 机器人
SpringAI
SpringAI整合全球主流大模型,支持多种技术架构,提供统一开发接口。本文以OpenAI和Ollama为例,详解如何通过SpringAI快速构建对话机器人,涵盖项目搭建、依赖引入与配置,助力开发者高效上手大模型应用开发。
|
人工智能 Java API
Java 也能快速搭建 AI 应用?一文带你玩转 Spring AI 可观测性
Java 也能快速搭建 AI 应用?一文带你玩转 Spring AI 可观测性
|
监控 安全 Java
Spring Boot最佳实践:从入门到精通
Spring Boot最佳实践:从入门到精通
|
存储 安全 Java
数据库轻松切换:解读Spring中的AbstractRoutingDataSource
数据库轻松切换:解读Spring中的AbstractRoutingDataSource
1162 0
|
Web App开发 JSON 网络安全
CURL发送POST请求
CURL发送POST请求
1491 0