1.java.lang.NoClassDefFoundError: org/apache/spark/api/java/function/Function0
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.spark.api.java.function.Function0
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Disconnected from the target VM, address: '127.0.0.1:52278', transport: 'socket'
Error: A JNI error has occurred, please check your installation and try again
解决办法:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_2.11</artifactId>
<version>2.1.1</version>
<scope>provided</scope>
</dependency>
因为依赖中设置了<scope>provied</scope>,provied是在编译和测试时有效,将provied改为compile或者删除掉即可
现在主要来说明<scope>值的作用范围:
compile:默认值,适用于所有阶段(表明该jar包在编译、运行以及测试中路径俊可见),并且会随着项目直接发布。
provided:编译和测试时有效,并且该jar包在运行时由服务器提供。如servlet-api.
runtime:运行时使用,对测试和运行有效。如jdbc.
test:只在测试时使用,在编译和运行时不起作用。发布项目时没有作用。
system:不依赖maven仓库解析,需要提供依赖的显式的置顶jar包路径。对项目的移植来说是不方便的。
2.java.lang.ClassNotFoundException: org.apache.spark.streaming.kafka.KafkaUtils
原因也是因为添加进来的依赖<scope>provided</scope>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka-0-8_2.11</artifactId>
<version>2.1.1</version>
<scope>provided</scope>
</dependency>
解决办法:<scope>provied</scope>
3.Reconnect due to error: java.lang.NoSuchMethodError: org.apache.kafka.common.network.NetworkSend.<init>(Ljava/lang/String;[Ljava/nio/ByteBuffer;)V
at kafka.network.RequestOrResponseSend.<init>(RequestOrResponseSend.scala:41) ~[kafka_2.11-0.10.0.1.jar:?] at kafka.network.RequestOrResponseSend.<init>(RequestOrResponseSend.scala:44) ~[kafka_2.11-0.10.0.1.jar:?] at kafka.network.BlockingChannel.send(BlockingChannel.scala:112) ~[kafka_2.11-0.10.0.1.jar:?] at kafka.consumer.SimpleConsumer.liftedTree1$1(SimpleConsumer.scala:85) [kafka_2.11-0.10.0.1.jar:?] at kafka.consumer.SimpleConsumer.kafka$consumer$SimpleConsumer$$sendRequest(SimpleConsumer.scala:83) [kafka_2.11-0.10.0.1.jar:?] at kafka.consumer.SimpleConsumer.getOffsetsBefore(SimpleConsumer.scala:149) [kafka_2.11-0.10.0.1.jar:?] at kafka.javaapi.consumer.SimpleConsumer.getOffsetsBefore(SimpleConsumer.scala:79) [kafka_2.11-0.10.0.1.jar:?]
原因是自己添加了kafka的依赖,估计和kafka-client发生了冲突,注释点即可
<!--<dependency>-->
<!--<groupId>org.apache.kafka</groupId>-->
<!--<artifactId>kafka_2.11</artifactId>-->
<!--<version>0.10.2.0</version>-->
<!--</dependency>-->
4.10-26 10:57:17[org.apache.hadoop.util.Shell-303][pool-19-thread-1][315990] - Failed to lo