Spark/SBT項目開發:
下載Scala SDK
下載SBT
配置IDEA SBT:(如果不配置,就會重新下載SBT, 非常慢,因為以前我已經下過了,所以要配置為過去使用的SBT)




新建立SBT項目:


導入Spark jars:

創建WordCount:
import org.apache.spark.{SparkConf, SparkContext}
object WordCountDemo {
def main(args: Array[String]): Unit = {
if (args.length < 1) {
System.err.println("Usage: <file>")
System.exit(1)
}
val conf = new SparkConf().setAppName("WordCount").setMaster("local")
val sc = new SparkContext(conf)
val line = sc.textFile(args(0))
line.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_ + _).collect().foreach(println)
sc.stop()
}
}

配置運行參數:

運行結果:

