scalac 编译产量 "object apache is not a member of package org"

scalac compile yields "object apache is not a member of package org"

我的代码是:

import org.apache.spark.SparkContext

在交互模式下可以运行,但是当我用scalac编译的时候,出现如下错误信息:

object apache is not a member of package org

这个好像是路径的问题,但是不知道具体怎么配置路径。

您需要指定编译 Scala 代码时使用的库的路径。这通常不是手动完成的,而是使用 Maven 或 sbt 等构建工具。您可以在 http://spark.apache.org/docs/1.2.0/quick-start.html#self-contained-applications

找到最小的 sbt 设置

我遇到这个问题是因为我的 pom.xml 文件中的 spark 依赖项范围错误。这是错误的:

<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-core_2.11</artifactId>
  <version>${spark.version}</version>
  <scope>test</scope> <!-- will not be available during compile phase -->
</dependency>

更改 test -> provided 会起作用 并且不会在您的 uberjar 中包含 spark,这几乎是您肯定想要的:

<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-core_2.11</artifactId>
  <version>${spark.version}</version>
  <scope>provided</scope>
</dependency>

一种简单的方法(如果您使用的是 Play Framework)是在 Maven Repository, choose the version, choose SBT 中查找 LibraryDependacy,然后将其添加到 project/build.sbt 文件的底部,像这样:

// https://mvnrepository.com/artifact/org.apache.spark/spark-core
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.3.2"

之后,您需要在 sbt 控制台中输入 reload,然后输入 compile。如果您来自 pipjs,这可能会有点陌生,但 Maven Repo 是您的朋友。

我在 sbt interactive 会话中遇到了这个问题。

通过简单地在会话中执行 reload 解决了问题。

希望对您有所帮助!

当 运行 spark 框架上的 scala wordcount 程序工作时,我遇到了同样的问题。 我使用 eclipse 作为 IDE 和 maven 作为构建工具。 我刚刚从 "test"-->"provided" 中删除了 POM 文件中的火花框架工作范围,如下所示。有效。 提供