运行与Jackson相关的项目,并遇到以下JsonMerge
not found错误。
Console
java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonMerge
at com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector.<clinit>(JacksonAnnotationIntrospector.java:50) ~[jackson-databind-2.9.0.pr1.jar:2.9.0.pr1]
at com.fasterxml.jackson.databind.ObjectMapper.<clinit>(ObjectMapper.java:292) ~[jackson-databind-2.9.0.pr1.jar:2.9.0.pr1]
at com.hostingcompass.core.utils.PrintUtils.<clinit>(PrintUtils.java:9) ~[main/:na]
at com.hostingcompass.app.run.TurtleApp.run(TurtleApp.java:25) ~[main/:na]
at com.hostingcompass.app.Main.run(Main.java:42) [main/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at com.hostingcompass.app.Main.main(Main.java:34) [main/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_77]
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:na]
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.annotation.JsonMerge
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_77]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_77]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_77]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_77]
... 17 common frames omitted
解
注意
查看上面的错误消息,该项目正在使用jackson-databind-2.9.0.pr1
要解决此问题, 2.8.x
Jackson降级到2.8.x
版本,最新的2.9.0.pr1
尚不稳定。 对于Gradle,请使用dependencyInsight
来查找jackson-databind
关系。
Terminal
$ gradle dependencyInsight --configuration compile --dependency jackson-databind
com.fasterxml.jackson.core:jackson-databind:2.9.0.pr1 (conflict resolution)
com.fasterxml.jackson.core:jackson-databind:2.8.2 -> 2.9.0.pr1
\--- com.maxmind.geoip2:geoip2:2.8.0
\--- compile
com.fasterxml.jackson.core:jackson-databind:2.8.7 -> 2.9.0.pr1
\--- compile
com.fasterxml.jackson.core:jackson-databind:[2.7.0,) -> 2.9.0.pr1
\--- com.maxmind.db:maxmind-db:1.2.1
\--- com.maxmind.geoip2:geoip2:2.8.0
\--- compile
要解决此问题,请从com.maxmind.geoip2
排除jackson-databind
:
build.gradle
dependencies {
compile "com.fasterxml.jackson.core:jackson-databind:2.8.7"
compile ('com.maxmind.geoip2:geoip2:2.8.0'){
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
}
}
参考文献
翻译自: https://mkyong.com/gradle/java-lang-noclassdeffounderror-comfasterxmljacksonannotationjsonmerge/