开发者社区> 问答> 正文

线程“main”中的异常java.lang.NoClassDefFoundError:scala / Product $ class

社区小助手 2018-12-19 15:53:36 1222

线程“main”中的异常java.lang.NoClassDefFoundError:scala / Product $ class
Buld.sbt

name := "BigData"

version := "0.1"

scalaVersion := "2.12.7"

libraryDependencies += "com.github.tototoshi" %% "scala-csv" % "1.3.5"
// https://mvnrepository.com/artifact/org.apache.spark/spark-core
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.4.0"

// https://mvnrepository.com/artifact/org.apache.spark/spark-sql
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.4.0"
// https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
libraryDependencies += "com.microsoft.sqlserver" % "mssql-jdbc" % "6.1.0.jre8"
libraryDependencies += "com.databricks" % "spark-xml_2.11" % "0.4.1"

// https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.19"
// https://mvnrepository.com/artifact/com.typesafe.akka/akka-http
libraryDependencies += "com.typesafe.akka" %% "akka-http" % "10.1.5"
// https://mvnrepository.com/artifact/com.typesafe.akka/akka-stream
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.5.19"

// https://mvnrepository.com/artifact/org.apache.livy/livy-core
libraryDependencies += "org.apache.livy" %% "livy-core" % "0.5.0-incubating"
使用scala和spark的代码

import org.apache.spark.sql.SparkSession

object sparkXml {
def main(args: Array[String]): Unit = {

val spark = SparkSession.
  builder.master("local[*]")
  //.config("spark.debug.maxToStringFields", "100")
  .appName("Insight Application Big Data")
  .getOrCreate()

val df = spark.read
  .format("com.databricks.spark.xml")
  .option("rowTag", "book")
  .load("src/main/resources/in/books.xml")
df.printSchema()

}
}
错误信息

Exception in thread "main" java.lang.NoClassDefFoundError: scala/Product$class

at com.databricks.spark.xml.XmlRelation.<init>(XmlRelation.scala:35)
at com.databricks.spark.xml.DefaultSource.createRelation(DefaultSource.scala:65)
at com.databricks.spark.xml.DefaultSource.createRelation(DefaultSource.scala:43)
at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:318)
at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:223)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:211)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:178)
at com.amkcambodia.insight.app.components.sparkXml$.main(sparkXml.scala:16)
at com.amkcambodia.insight.app.components.sparkXml.main(sparkXml.scala)

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:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more

18/12/16 07:15:17 INFO SparkContext: Invoking stop() from shutdown hook

分布式计算 Scala Spark
分享到
取消 提交回答
全部回答(1)
+ 订阅

大数据计算实践乐园,近距离学习前沿技术

推荐文章
相似问题
推荐课程