java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/json/JsonWriteFeature
原因是需要的fasterxml的版本包和其他包里面的旧版本重复而丢弃
运行命令:mvn dependency:tree -Dverbose -Dincludes=*fasterxml*:*databind*
找出所有包含*fasterxml*:*jackson*
的包:
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ sr-flow-api ---
[INFO] com.huawei.ccloud.sparkle.search:sr-flow-api:jar:1.0.0-SNAPSHOT
[INFO] +- org.apache.spark:spark-mllib_2.12:jar:3.0.1:provided
[INFO] | +- org.apache.spark:spark-core_2.12:jar:3.0.1:provided
[INFO] | | +- org.apache.spark:spark-kvstore_2.12:jar:3.0.1:provided
[INFO] | | | \- (com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:provided - omitted for duplicate)
[INFO] | | +- org.apache.spark:spark-network-common_2.12:jar:3.0.1:provided
[INFO] | | | \- (com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:provided - omitted for duplicate)
[INFO] | | +- io.dropwizard.metrics:metrics-json:jar:4.1.1:provided
[INFO] | | | \- (com.fasterxml.jackson.core:jackson-databind:jar:2.9.9.3:provided - omitted for conflict with 2.10.0)
[INFO] | | +- (com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:provided - omitted for conflict with 2.6.3)
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-scala_2.12:jar:2.10.0:provided
[INFO] | | +- (com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:provided - omitted for duplicate)
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-paranamer:jar:2.10.0:provided
[INFO] | | \- (com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:provided - omitted for duplicate)
[INFO] | \- org.apache.spark:spark-sql_2.12:jar:3.0.1:provided
[INFO] | \- (com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:provided - omitted for duplicate)
[INFO] +- org.apache.kafka:kafka-streams:jar:0.10.0.0:provided
[INFO] | +- org.apache.kafka:connect-json:jar:0.10.0.0:provided
[INFO] | | \- (com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:provided - omitted for conflict with 2.10.0)
[INFO] | \- com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:provided
[INFO] +- org.apache.spark:spark-hive_2.12:jar:3.0.1:provided
[INFO] | \- org.apache.hive:hive-common:jar:2.3.7:provided
[INFO] | \- (com.fasterxml.jackson.core:jackson-databind:jar:2.6.5:provided - omitted for conflict with 2.6.3)
[INFO] \- org.json4s:json4s-jackson_2.12:jar:4.1.0-M2:provided
[INFO] \- org.json4s:json4s-jackson-core_2.12:jar:4.1.0-M2:provided
[INFO] \- (com.fasterxml.jackson.core:jackson-databind:jar:2.13.4.2:provided - omitted for conflict with 2.6.3)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.620 s
[INFO] Finished at: 2023-03-23T10:20:04+08:00
[INFO] ------------------------------------------------------------------------
Process finished with exit code 0
找到相关jar包的pom引入处(如果父pom中用了 dependencyManagement,直接再父pom中修改,就可以影响所有子pom了),加上:
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
例如:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_2.12</artifactId>
<version>${spark.version}</version>
<scope>${fi.scope}</scope>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
加完后再执行命令可以看到,没有冲突了:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ sr-flow-api ---
[INFO] com.huawei.ccloud.sparkle.search:sr-flow-api:jar:1.0.0-SNAPSHOT
[INFO] \- org.json4s:json4s-jackson_2.12:jar:4.1.0-M2:provided
[INFO] \- org.json4s:json4s-jackson-core_2.12:jar:4.1.0-M2:provided
[INFO] \- com.fasterxml.jackson.core:jackson-databind:jar:2.13.4.2:provided
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.871 s
[INFO] Finished at: 2023-03-23T10:25:45+08:00
[INFO] ------------------------------------------------------------------------
Process finished with exit code 0
若mvn命令跑出来的结果已经更新,但是是idea没有更新:
则File->Invalidate caches 清除缓存重启即可:
实际上,要想解决java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/json/JsonWriteFeature问题,还没结束,还要将以下两个jar包冲突排除,用一样的方法:文章来源:https://www.toymoban.com/news/detail-737947.html
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
文章来源地址https://www.toymoban.com/news/detail-737947.html
到了这里,关于报错NoClassDefFoundError: com/fasterxml/jackson/core/json/JsonWriteFeature; omitted for conflict with的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!