問題描述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