【发布时间】:2017-10-14 23:36:34
【问题描述】:
我是spark新手,关注tutorial学习。我已经安装 openjdk 版本“1.8.0_121”(web-binary) Hadoop 2.8.0(网络二进制) 斯卡拉版本 2.11.8 (apt) 和 spark 版本 2.1.1(web-binary-pre-build-with-hadoop 2.6.0 或更高版本)。
我运行了 SparkPi 示例并成功。但是,当我尝试使用通过org said 安装的sbt 0.13.15(apt) 打包我的第一个spark 应用程序时,出现了一些错误。
我知道某处的设置一定是错误的,但在this link 中找不到。谁能帮助我?谢谢:)
我的项目是这样的:
---SparkApp
|---simple.sbt
|---src
|---main
|---scala
|--- SimpleApp.scala
我项目中的点sbt文件是:
name := "Simple Project"
version := "0.13.15"
scalaVersion := "2.11.8"
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.1.1"
错误日志是这样的:
hadoop@master:~/Mycode/SparkApp$ sbt package
[warn] Executing in batch mode.
[warn] For better performance, hit [ENTER] to switch to interactive mode, or
[warn] consider launching sbt without any commands, or explicitly passing 'shell'
[info] Loading project definition from /home/hadoop/Mycode/SparkApp/project
[info] Set current project to Simple Project (in build file:/home/hadoop/Mycode/SparkApp/)
[info] Compiling 1 Scala source to /home/hadoop/Mycode/SparkApp/target/scala-2.11/classes...
[error] missing or invalid dependency detected while loading class file 'SparkContext.class'.
[error] Could not access term akka in package <root>,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'SparkContext.class' was compiled against an incompatible version of <root>.
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 2 s, completed May 16, 2017 1:08:53 PM
一些提示可能是问题所在:
- 当我输入 spark-shell 时,我得到了这个 Using Scala version 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131) ,这与我输入时不同输入 java -version openjdk 版本“1.8.0_121”。这会是问题吗?
- 安装 sbt 后我什么也没做。我应该为设置做点什么吗?比如让 sbt 知道我的 scala 和 spark 的位置。如何?
- 我没有 maven,是吗?
------------ 第二次编辑 -------
在dot sbt 文件中添加-Ylog-classpath 后,如this link 所说。我得到了一个很长的类路径打印出来,太长了,无法在此处显示。 问题尚未解决。
如前所述,我提供 SimpleApp.scala :
/* SimpleApp.scala */
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
object SimpleApp {
def main(args: Array[String]) {
val logFile = "file:///usr/local/spark/README.md" // Should be some file on your system
val conf = new SparkConf().setAppName("Simple Application")
val sc = new SparkContext(conf)
val logData = sc.textFile(logFile, 2).cache()
val numAs = logData.filter(line => line.contains("a")).count()
val numBs = logData.filter(line => line.contains("b")).count()
println("Lines with a: %s, Lines with b: %s".format(numAs, numBs))
}
}
【问题讨论】:
-
@Rahul 我应该尝试使用 Intellij 吗?
-
你可以试试。在 Spark 和 Scala 开发方面,intelliJ 是最好的 IDE,而且插件随时可用。
-
另外,您能否在 build.sbt 中添加 %provided a end 您的依赖项并尝试? libraryDependencies += "org.apache.spark" %% "spark-core" % "2.1.1" % "provided"
-
@Rahul 感谢您的建议,我的问题已经解决。我仍然在我的代码中使用了你的解决方案。
标签: scala apache-spark sbt