scala 控制台错误:对象 apache 不是包 org 的成员

scala 控制台错误:对象 apache 不是包 org 的成员

问题描述:

我正在尝试这里提出的代码:http://spark.apache.org/docs/1.2.1/mllib-ensemble.html#classification

I am trying the code proposed here: http://spark.apache.org/docs/1.2.1/mllib-ensembles.html#classification

使用 Scala 控制台(Scala 版本 = Scala 代码运行器版本 2.10.4),并得到以下错误:

using the Scala console (Scala version = Scala code runner version 2.10.4), and get the following error:

scala> import org.apache.spark.mllib.tree.RandomForest
<console>:8: error: object apache is not a member of package org
           import org.apache.spark.mllib.tree.RandomForest
                      ^

然后我遵循了此处的建议,并尝试构建一个简单的自包含应用程序,但遇到了不同的问题:

I then followed the advice from here and tried to build a simple self-contained application, but ran into a different problem:

root@sd:~/simple# sbt package
[info] Set current project to Simple Project (in build file:/root/simple/)
[info] Updating {file:/root/simple/}default-c5720e...
[info] Resolving org.scala-lang#scala-library;2.10.4 ...
[info] Resolving org.apache.spark#spark-core_2.10.4;1.2.0 ...
[warn]  module not found: org.apache.spark#spark-core_2.10.4;1.2.0
[warn] ==== local: tried
[warn]   /root/.ivy2/local/org.apache.spark/spark-core_2.10.4/1.2.0/ivys/ivy.xml
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/org/apache/spark/spark-core_2.10.4/1.2.0/spark-core_2.10.4-1.2.0.pom
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.apache.spark#spark-core_2.10.4;1.2.0: not found

谁能建议我可以尝试什么?

Can anyone advise what I could try?

详细步骤可以在 这篇文章 如何在 Scala 中使用 SBT 编写自包含的 Spark 应用程序.在 sbt 配置文件中你应该指定依赖库.

You can find detailed steps in this post how to write self contained Spark application using SBT in Scala. In sbt configuration file you should specify the dependent libraries.

libraryDependencies ++= Seq("org.apache.spark" % "spark-core_2.10" % "1.2.1",
"org.apache.spark" % "spark-mllib_2.10" % "1.2.1")

然后使用以下命令编译

sbt package