1 源码
package demo
import org.apache.spark.{SparkConf, SparkContext}
object WordCount {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("wc")
//非常重要,通向Spark集群的入口
val sc = new SparkContext(conf)
sc.textFile(args(0)).flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_).sortBy(_._2,false).saveAsTextFile(args(1))
sc.stop()
}
}
maven 打包成 jar
2 重新修改源码
package demo
import org.apache.spark.{SparkConf, SparkContext}
object WordCount {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("WC")
.setJars(Array("D:\\Data\\JavaProject\\hellospark\\target\\hellospark-1.0-SNAPSHOT.jar"))
.setMaster("spark://node1:7077")
//非常重要,通向Spark集群的入口
val sc = new SparkContext(conf)
sc.textFile(args(0)).flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_).sortBy(_._2,false).saveAsTextFile(args(1))
sc.stop()
}
}