我在scala中运行spark wordcount时在eclipse中遇到错误

dm7nw8vv  于 2021-06-02  发布在  Hadoop
关注(0)|答案(2)|浏览(300)

这个问题在这里已经有答案了

scala项目不会在eclipse中编译找不到主类。“(12个答案)
三年前关门了。
我的scala程序:

  1. import org.apache.spark._
  2. import org.apache.spark.SparkContext._
  3. object WordCount {
  4. def main(args: Array[String]) {
  5. val inputFile = args(0)
  6. val outputFile = args(1)
  7. val conf = new SparkConf().setAppName("wordCount")
  8. // Create a Scala Spark Context.
  9. val sc = new SparkContext(conf)
  10. // Load our input data.
  11. val input = sc.textFile(inputFile)
  12. // Split up into words.
  13. val words = input.flatMap(line => line.split(" "))
  14. // Transform into word and count.
  15. val counts = words.map(word => (word, 1)).reduceByKey{case (x, y) => x + y}
  16. // Save the word count back out to a text file, causing evaluation.
  17. counts.saveAsTextFile(outputFile)
  18. }
  19. }

我得到的错误:

  1. Error: Could not find or load main class WordCount
xzlaal3s

xzlaal3s1#

您尚未设置master的属性。

  1. val conf = new SparkConf().setAppName("wordCount").setMaster(local[*])
jgwigjjp

jgwigjjp2#

我想可能是类路径的问题,设置不正确。
如果您使用的是intellij,那么将该目录标记为源根目录就可以做到这一点。

相关问题