gpt4 book ai didi

scala - NoClassDefFoundError:SparkSession-即使构建正常

转载 作者:行者123 更新时间:2023-12-03 14:39:50 25 4
gpt4 key购买 nike

我将https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark/examples/ml/RandomForestClassifierExample.scala复制到一个新项目中并设置一个build.sbt

name := "newproject"
version := "1.0"
scalaVersion := "2.11.8"

javacOptions ++= Seq("-source", "1.8", "-target", "1.8")
scalacOptions += "-deprecation"

libraryDependencies ++= Seq(
"org.apache.spark" % "spark-core_2.11" % "2.0.0" % "provided",
"org.apache.spark" % "spark-sql_2.11" % "2.0.0" % "provided",
"org.apache.spark" % "spark-mllib_2.11" % "2.0.0" % "provided",
"org.jpmml" % "jpmml-sparkml" % "1.1.1",
"org.apache.maven.plugins" % "maven-shade-plugin" % "2.4.3",
"org.scalatest" %% "scalatest" % "3.0.0"
)


我可以从IntelliJ 2016.2.5中构建它,但是当我收到错误消息时

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/sql/SparkSession$
at org.apache.spark.examples.ml.RandomForestClassifierExample$.main(RandomForestClassifierExample.scala:32)
at org.apache.spark.examples.ml.RandomForestClassifierExample.main(RandomForestClassifierExample.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: org.apache.spark.sql.SparkSession$
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)
... 7 more


我什至可以单击SparkSession并获取源代码。问题是什么?

最佳答案

当您对依赖项说provided时,构建将针对该依赖项进行编译,但不会在运行时将其添加到类路径中(假定已经存在)。

这是为spark-submit构建Spark作业时的正确设置(因为它们将在确实提供依赖项的Spark容器中运行,并且再次包含该依赖项会造成麻烦)。

但是,在本地运行时,需要存在该依赖项。因此,要么将构建更改为不具有此provided(但是在构建以提交作业时您需要对其进行调整),或者在IDE中将运行时类路径配置为已具有该jar文件。

关于scala - NoClassDefFoundError:SparkSession-即使构建正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40383880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com