【问题标题】:Error: Could not find or load main class with Spark in Eclipse错误:无法在 Eclipse 中使用 Spark 找到或加载主类
【发布时间】:2017-06-30 06:48:56
【问题描述】:

从 Eclipse (scala) 运行 spark 应用程序时遇到问题。但是我可以从 Eclipse 运行 Scala 而没有任何问题;该问题似乎只出现在 spark 应用程序中。

错误:无法找到或加载主类 com.sidSparkScala.RatingsCounter*

package com.sundogsoftware.spark

import org.apache.spark._
import org.apache.spark.SparkContext._
import org.apache.log4j._

/** 
  * Count up how many of each star rating exists in the MovieLens 
  * 100K data set.
  */
object RatingsCounter {

  /** Our main function where the action happens */
  def main(args: Array[String]) {

    // Set the log level to only print errors
    Logger.getLogger("org").setLevel(Level.ERROR)

    // Create a SparkContext using every core of the local machine, named RatingsCounter
    val sc = new SparkContext("local[*]", "RatingsCounter")

    // Load up each line of the ratings data into an RDD
    val lines = sc.textFile("../ml-100k/u.data")

    // Convert each line to a string, split it out by tabs, and extract the third field.
    // (The file format is userID, movieID, rating, timestamp)
    val ratings = lines.map(x => x.toString().split("\t")(2))

    // Count up how many times each value (rating) occurs
    val results = ratings.countByValue()

    // Sort the resulting map of (rating, count) tuples
    val sortedResults = results.toSeq.sortBy(_._1)

    // Print each result on its own line.
    sortedResults.foreach(println)

  }

}

【问题讨论】:

  • 你是否在eclipse ide中为你的项目添加了scala性质???
  • 抱歉这个幼稚的问题,package 语句实际上是缺失还是您忘记粘贴在这里?
  • 你给了正确的包名。我猜包名有些不匹配。
  • 其实包名不匹配。一旦我给出了正确的名称,它就会很好地工作。不知道我是如何忽略这么一件小事并花了一整天时间来解决这个问题的:)。很棒的收获。非常感谢。

标签: eclipse scala apache-spark


【解决方案1】:

您最初创建的包名似乎是com.sidSparkScala.RatingsCounter,脚本中提到的包名是com.sundogsoftware.spark(在顶部)。您所要做的就是将包com.sundogsoftware.spark 替换为com.sidSparkScala.RatingsCounter

【讨论】:

    【解决方案2】:

    你的类没有正确编译,否则eclipse可以找到这个类。请检查,是否有编译错误。

    【讨论】:

      【解决方案3】:

      您必须将软件包名称更改为您的,而不是提供的课程。 我猜你从 external import 这个 scala 文件,基于上面的代码,包是 com.sundogsoftware.spark ,把它改成你的会好的。

      【讨论】:

        猜你喜欢
        • 2012-06-29
        • 2014-06-26
        • 1970-01-01
        • 1970-01-01
        • 2015-02-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多