maven项目添加依赖 json后, mvn clean package 打包maven项目报错 Found multiple occurrences of org.json.JSONObject on the class path
具体错误信息如下:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.4.RELEASE)
2019-07-10 02:24:13.983 WARN 84180 --- [ main] ory$DuplicateJsonObjectContextCustomizer :
Found multiple occurrences of org.json.JSONObject on the class path:
jar:file:/E:/maven_repository_new/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class
jar:file:/E:/maven_repository_new/org/json/json/20160810/json-20160810.jar!/org/json/JSONObject.class
You may wish to exclude one of them to ensure predictable runtime behavior
字面意思:有2个地方冲突的 json 依赖,需要 排除(exclude )一个
解决办法:
下面那个 json-20160810.jar 是我自己添加的json依赖希望保留,那么就需要排除掉 android-json 这个依赖。
首先我们需要知道这个 android-json 是在哪个依赖里面,pom.xml 直接搜肯定是找不到 android-json的。
寻找看不到的 依赖 android-json,右键pom.xml->Maven->Show Dependencies
在这个所有依赖的界面搜索 android-json , 按crtl + f , 输入字符 “an” 就可以看到 android-json了
点击 android-json ,可以根据依赖线箭头发现 android-json 在 spring-boot-starter-test 里面
那么剩下的就简单了,在 spring-boot-starter-test 里面排除依赖 android-json ,如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
最后
要学会举一反三,其他的一些影藏的依赖包冲突 也可以这样去寻找解决!