首页  

springboot应用jar包冲突解决实例     所属分类 java 浏览量 1214
eclipse 运行 main 方法 ,启动失败
编译之后war里的jar包版本是ok的

Caused by: java.lang.NoSuchMethodError: org.apache.http.util.Asserts.check(ZLjava/lang/String;Ljava/lang/Object;)

2个子项目 A 和 B 

main 方法 在 B项目中

main方法 /  run as  / Run Configuration / classpath

可以分别看到 子项目的 classpath 设置 
这里无法编辑 

A 项目中 httpclient 使用了旧版本

先直接修改 A 项目的 .classpath 文件 , 或者在 eclipse里修改A项目的classpath




<!--
  <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpclient/4.3.1/httpclient-4.3.1.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpclient/4.3.1/httpclient-4.3.1-sources.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpcore/4.3/httpcore-4.3.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpcore/4.3/httpcore-4.3-sources.jar"/>
-->
  <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpclient/4.5.5/httpclient-4.5.5.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpclient/4.5.5/httpclient-4.5.5-sources.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpcore/4.4.9/httpcore-4.4.9.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpcore/4.4.9/httpcore-4.4.9-sources.jar"/>





再次启动 还是报错

java.io.IOException: invalid constant type: 18 

dubbo 使用了 javassist
A 项目中使用了 老版本

先直接修改 A 项目的 .classpath 文件




<!--
  <classpathentry kind="var" path="M2_REPO/org/javassist/javassist/3.15.0-GA/javassist-3.15.0-GA.jar" sourcepath="M2_REPO/org/javassist/javassist/3.15.0-GA/javassist-3.15.0-GA-sources.jar"/>
-->
<classpathentry kind="var" path="M2_REPO/org/javassist/javassist/3.19.0-GA/javassist-3.19.0-GA.jar" sourcepath="M2_REPO/org/javassist/javassist/3.19.0-GA/javassist-3.19.0-GA-sources.jar"/>



再次重启 ,搞定 

A 项目 代码中 使用了 httpclient 
需要强制指定版本 

没有直接使用  javassist 可以排除该依赖

mvn dependency:tree
mvn dependency:tree -Dverbose
mvn dependency:tree -Dverbose -Dincludes=xxx:yyy


终极解决方案 修改 pom.xml 增加依赖



<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.2</version>
</dependency>

<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.19.0-GA</version>
</dependency>



上一篇     下一篇
AQS同步队列与条件队列

公平锁与非公平锁的关键区别

自定义注解实例

eclipse中分析pom文件

maven依赖排除

maven中央仓库及镜像设置