前置准备

1.安装jdk1.8
2.安装idea
3.安装maven,编译spark对maven版本有要求,spark2.4.5需要maven3.5.4以上,建议安装最新版本的maven
image.png
4.安装scala
5.安装git,编译spark源码依赖bash命令,git中带有bash命令。并在环境变量path中配置git的路径
image.png

在环境变量path中配置git路径。
image.png

在cmd中输入bash命令,如果能进入bash视图则成功
6.下载spark源码
https://github.com/apache/spark
https://archive.apache.org/di...

编译Spark

1.在maven的settings中加入阿里的镜像

<mirror>
    <id>nexus-osc</id>
    <mirrorOf>central</mirrorOf>
    <name>Nexus osc</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>

2.idea中配置maven
image.png

3.导入spark源码
image.png

4.编译spark源码,其中hadoop版本可以根据实际情况选择
image.png

image.png

5.如果所有模块都编译成功,则spark源码编译成功
image.png

运行JavaWordCount例子

1.在examples模块下找到JavaWordCount.java代码,打开
image.png

2.编辑参数,需要填写如下参数
VM options: -Dspark.master=local (local模式运行,即本地单线程运行)
Program arguments: D:wordcount.txt (这是文件路径,需要新建文件)
image.png
image.png
注:需要勾选上Include dependencies with "Provided" scope选项。因为examples模块下的pom文件中的依赖配置的scope都是provided,不配置会报java.lang.NoClassDefFoundError: org/apache/spark/sql/SparkSession
image.png

3.右键-> Debug 'JavaWordCount.main'
image.png

4.如果控制台输出单词的统计数,则运行成功
image.png

参考

http://spark.apache.org/docs/...
https://blog.csdn.net/qq_3582...
https://blog.csdn.net/l_15156...


bugDesigner
22 声望3 粉丝