我试图使用IntelliJ运行一个极其琐碎的火花上下文实例。但是,我遇到了一个我收到NoClassDefFoundError
的问题:
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Product$class
at org.apache.spark.SparkConf$DeprecatedConfig.<init>(SparkConf.scala:609)
at org.apache.spark.SparkConf$.<init>(SparkConf.scala:473)
at org.apache.spark.SparkConf$.<clinit>(SparkConf.scala)
at org.apache.spark.SparkConf.set(SparkConf.scala:71)
at org.apache.spark.SparkConf.setAppName(SparkConf.scala:86)
at test$.main(test.scala:8)
at test.main(test.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:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: scala.Product$class
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 12 more
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
17/01/27 00:24:37 INFO Utils: Shutdown hook called
我尝试将所有内容从我的Sbt版本转移到Scala版本。以下是我的配置:
我试图运行此代码:
import org.apache.spark.{SparkConf, SparkContext}
object test {
def main(args: Array[String]): Unit = {
val conf = new SparkConf()
conf.setAppName("test")
conf.setMaster("local[2]")
val sc = new SparkContext(conf)
println(sc)
}
}
有什么我不了解Scala和Spark版本的不兼容性吗?
答案 0 :(得分:2)
显式添加Scala库和xml依赖项
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.4</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-xml</artifactId>
<version>2.11.0-M4</version>
</dependency>