问题描述:使用maven创建一个SparkStreaming工程,引入pom文件后,明明ja包已经导入到maven库中了,且也可以导入到项目中,但是在执行SparkStreaming代码时,始终提示找不到类。错误信息如下所示:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/streaming/StreamingContext
at DSDemo$.main(DSDemo.scala:18)
at DSDemo.main(DSDemo.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.apache.spark.streaming.StreamingContext
pom文件如下:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_2.11</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>
解决办法:
将<scope>provided</scope> 节点去掉,采用默认的compile值。