【发布时间】:2016-06-22 21:59:53
【问题描述】:
我想运行 spark-coreNLP example,但在运行 spark-submit 时出现 java.lang.ClassNotFoundException 错误。
这是来自 github 示例的 scala 代码,我将其放入一个对象中,并定义了一个 SparkContext。
analyzer.Sentiment.scala:
package analyzer
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
import org.apache.spark.sql.functions._
import com.databricks.spark.corenlp.functions._
import sqlContext.implicits._
object Sentiment {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Sentiment")
val sc = new SparkContext(conf)
val input = Seq(
(1, "<xml>Stanford University is located in California. It is a great university.</xml>")
).toDF("id", "text")
val output = input
.select(cleanxml('text).as('doc))
.select(explode(ssplit('doc)).as('sen))
.select('sen, tokenize('sen).as('words), ner('sen).as('nerTags), sentiment('sen).as('sentiment))
output.show(truncate = false)
}
}
我使用的是 spark-coreNLP 提供的 build.sbt - 我只修改了我自己的 scalaVersion 和 sparkVerison。
version := "1.0"
scalaVersion := "2.11.8"
initialize := {
val _ = initialize.value
val required = VersionNumber("1.8")
val current = VersionNumber(sys.props("java.specification.version"))
assert(VersionNumber.Strict.isCompatible(current, required), s"Java $required required.")
}
sparkVersion := "1.5.2"
// change the value below to change the directory where your zip artifact will be created
spDistDirectory := target.value
sparkComponents += "mllib"
spName := "databricks/spark-corenlp"
licenses := Seq("GPL-3.0" -> url("http://opensource.org/licenses/GPL-3.0"))
resolvers += Resolver.mavenLocal
libraryDependencies ++= Seq(
"edu.stanford.nlp" % "stanford-corenlp" % "3.6.0",
"edu.stanford.nlp" % "stanford-corenlp" % "3.6.0" classifier "models",
"com.google.protobuf" % "protobuf-java" % "2.6.1"
)
然后,我通过运行没有问题创建了我的 jar。
sbt package
最后,我将我的工作提交给 Spark:
spark-submit --class "analyzer.Sentiment" --master local[4] target/scala-2.11/sentimentanalizer_2.11-0.1-SNAPSHOT.jar
但我收到以下错误:
java.lang.ClassNotFoundException: analyzer.Sentiment
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.spark.util.Utils$.classForName(Utils.scala:173)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:641)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
我的文件 Sentiment.scala 正确位于名为“analyzer”的包中。
$ find .
./src
./src/analyzer
./src/analyzer/Sentiment.scala
./src/com
./src/com/databricks
./src/com/databricks/spark
./src/com/databricks/spark/corenlp
./src/com/databricks/spark/corenlp/CoreNLP.scala
./src/com/databricks/spark/corenlp/functions.scala
./src/com/databricks/spark/corenlp/StanfordCoreNLPWrapper.scala
当我从 Spark Quick Start 运行 SimpleApp 示例时,我注意到 MySimpleProject/bin/ 包含一个 SimpleApp.class。 MySentimentProject/bin 是空的。所以我试图清理我的项目(我正在使用 Eclipse for Scala)。
我认为这是因为我需要生成 Sentiment.class,但我不知道该怎么做 - 它是使用 SimpleApp.scala 自动完成的,当它尝试使用 Eclipse Scala 运行/构建时,它崩溃了.
【问题讨论】:
-
我在 Sentiment.scala 的开头没有看到
package analyzer。在名为“analyzer”的目录中是不够的,因为 Scala 允许您将文件名和目录与类和包分离。 -
我在 Sentiment.scala 的开头添加了“包分析器”。没有效果。我还将我的 scala 版本从 2.11 更改为 2.10.6,使其具有与 spark-corenlp 相同的配置,但没有任何效果。
标签: scala apache-spark stanford-nlp