【发布时间】: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