1.maven项目
pom.xml
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.12</artifactId>
<version>3.0.0</version>
<!-- <scope>provided</scope>-->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<!--程序入口,jar的主函数-->
<manifest>
<mainClass>numCount.main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
com.test.list.numCount
package com.test.list
import org.apache.spark.{SparkConf, SparkContext}
object numCount {
def main(args: Array[String]): Unit = {
//TODO 准备环境
val sparkConf = new SparkConf().setMaster("local[*]").setAppName("numCount")
val sc = new SparkContext(sparkConf)
//TODO 算子 - map
val list = sc.makeRDD(List(1,2,3,4,5,6,7,2,8),2)
val value = list.sortBy(num=>num, true, 4)
value.collect().foreach(println)
//TODO 关闭环境
sc.stop()
}
def mapFunction(num:Int):Int = {
num * 2
}
}
2.打包项目为jar上传至虚拟机目录

3.提交运行
bin/spark-submit # 提交入口
–class com.test.list.numCount #jar代码中java的子包名
–master local[2] #设置核数
examples/jars/spark-numCount-test.jar #jar位置
bin/spark-submit --class com.test.list.numCount --master local[2] examples/jars/spark-numCount-test.jar
4.运行截图

2905



被折叠的 条评论
为什么被折叠?



