Mavenjar包冲突的问题解决(亲测有效、实力证明)
一、今天在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>
九、写完后就会发现,冲突的包不见了,就解决啦
最后再启动项目,就会成功了。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Python将md批量转为docx
这两天写毕业论文, 发现了一个可以将markdown快速转为word格式的小工具pandoc, 非常好用, 比如我有一个名为毕业论文.md的文件, 我只需在命令行运行 pandoc 毕业论文.md -o 毕业论文.docx 即可根据md文件生成新的docx文件! pandoc支持相互转换的格式, 多的惊人! pandoc Pandoc主站链接 安装包下载地址 https://github.com/jgm/pandoc/releases/tag/2.2 使用技巧: 由于word确实很难用, 我们可以用md格式书写, 然后转换成docx 懒是第一生产力, pandoc可以在命令行运行, 所以, 我们可以配合python脚本将md格式批量转换为docx 这是我写的一个简易脚本 import os def auto_md_to_docx(file_dir): # 获取当前目录下所有的md文件的路径信息 all_whole_path_files = [] for root, dirs, files in os.walk(file_dir): for file in files: try: if ...
- 下一篇
gdb kernel debug的进程断点
gdb调试kernel的时候, 如果设置通用函数断点, 比如vfs_read, 就会遇到一堆撞到断点的地方, 比如tty输入一个字符, 就是vfs_read, 没办法调试具体的某一个进程 一种办法就是条件断点, 其实不是很好用, 比如用pid, 但是有时候这个进程还没启动, 比如task的comm来判定, 但是kernel中是不支持strcmp来判断字符串是否相等, 因为需要跑函数 gdb 7.5对此问题做了增强, gdb自己去比较字符串, 而不需要机器去跑代码 https://sourceware.org/gdb/current/onlinedocs/gdb/Convenience-Funs.html#Convenience-Funs b do_fault if $_streq($lx_current()->comm, "a.ou
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS8编译安装MySQL8.0.19
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- SpringBoot2整合Redis,开启缓存,提高访问速度
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- Hadoop3单机部署,实现最简伪集群
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果