问题描述java
今天在作项目过程当中,在使用java语言建立DataFrame在窗口打印数据,编译时老是报错,经过查阅资料最终问题获得解决。记录以下:开发环境为spark2.3 + kafka0.9.0。编辑软件使用的 IntelliJ IDEA,使用的语言是java语言。在进行ds的输出时出现以下错误:git
Exception in thread “main” java.lang.NoSuchMethodError: net.jpountz.lz4.LZ4BlockInputStream.(Ljava/io/InputStream;Z)Vgithub
at org.apache.spark.io.LZ4CompressionCodec.compressedInputStream(CompressionCodec.scala:122)sql
at org.apache.spark.sql.execution.SparkPlan.orgapachesparksqlexecutionSparkPlan$decodeUnsafeRows(SparkPlan.scala:274)apache
at org.apache.spark.sql.execution.SparkPlan$anonfun anonfunanonfunexecuteTake$1.apply(SparkPlan.scala:366)
…
at com.spark.session.UserVisitSessionAnalyzeSpark.main(UserVisitSessionAnalyzeSpark.java:72)session
错误展现app
1.spark2.3用到了lz4-1.3.0.jar,kafka0.9.0.1用到了lz4-1.2.0.jar,而程序运行时使用的是lz4-1.3.0.jar。spa
2.lz4-1.3.0.jar包中net.jpountz.util.Utils 类中没有checkRange,该方法位于net.jpountz.util.SafeUtils和net.jpountz.util.UnsafeUtilsscala
在pom.xml文件中添加此配置项目。code
<dependency> <groupId>net.jpountz.lz4</groupId> <artifactId>lz4</artifactId> <version>1.3.0</version> </dependency>
错误获得解决,能够看到结果。
1.从新编译org.apache.kafka.common.message.KafkaLZ4BlockInputStream类,将调用net.jpountz.util.Utils.checkRange方法的地方改成 net.jpountz.util.SafeUtils.checkRange
2.将编译后的class文件覆盖spark-streaming-kafka-0-8-assembly_2.11.jar包的文件
说明:上面的方法解决问题简单实用,所以采用了上述方法,下面这两种方法有兴趣你们本身能够试试。
参考网址:
https://github.com/apache/kafka/commit/69269e76a43adf85a478240280c6ab3c7eef4d8e
https://stackoverflow.com/questions/48446773/nosuchmethoderror-with-spark-streaming-2-2-0-and-kafka-0-8