Exception in thread "dispatcher-event-loop-1" java.lang.NoClassDefFoundError: com/fasterxml/jackson/

笪成周
2023-12-01

启动Spark时(CDH版本较常见),报如下错误:

19/02/20 00:20:33 INFO StandaloneRestServer: Started REST server for submitting applications on port 6066
Exception in thread "dispatcher-event-loop-1" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/Module
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at org.apache.spark.util.Utils$.classForName(Utils.scala:177)
	at org.apache.spark.metrics.MetricsSystem$$anonfun$registerSinks$1.apply(MetricsSystem.scala:196)
	at org.apache.spark.metrics.MetricsSystem$$anonfun$registerSinks$1.apply(MetricsSystem.scala:192)
	at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:98)
	at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:98)
	at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:226)
	at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:39)
	at scala.collection.mutable.HashMap.foreach(HashMap.scala:98)
	at org.apache.spark.metrics.MetricsSystem.registerSinks(MetricsSystem.scala:192)
	at org.apache.spark.metrics.MetricsSystem.start(MetricsSystem.scala:100)
	at org.apache.spark.deploy.master.Master.onStart(Master.scala:160)
	at org.apache.spark.rpc.netty.Inbox$$anonfun$process$1.apply$mcV$sp(Inbox.scala:121)
	at org.apache.spark.rpc.netty.Inbox.safelyCall(Inbox.scala:204)
	at org.apache.spark.rpc.netty.Inbox.process(Inbox.scala:100)
	at org.apache.spark.rpc.netty.Dispatcher$MessageLoop.run(Dispatcher.scala:217)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.Module
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 20 more

原因是CDH版本jar缺少。。
解决办法:
使用maven或者去jar仓库下载对应的三个json的jar包:
Maven依赖:

    <dependency>
              <groupId>com.fasterxml.jackson.core</groupId>
              <artifactId>jackson-databind</artifactId>
              <version>2.4.4</version>
    </dependency>
    <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-core</artifactId>
         <version>2.4.4</version>
     </dependency>
     <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-annotations</artifactId>
         <version>2.4.4</version>
     </dependency>

下载完成后去对应本地仓库目录将jar文件添加到hadoop/share/hadoop/common/下。顺便再spark的lib下也添加一下,反正没啥影响,添加完就可以启动成功了。。。

 类似资料: