环境:
scala:2.12.0
java:1.8
spark:3.1.2
一、Idea创建scala项目
Idea新建一个新的项目,选择通过maven创建:
给项目起个名字,设置版本:
maven选项,如果有本地maven的话用本地的,没有的话建议下一个,不行用这个默认的也可以:
设置maven源为aliyun,上面的setting目录创建对应的setting.xml文件:
(base) [~/softwares]$ cat /home/ffzs/.m2/settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
这里创建的scala项目中默认使用的是scala 2.7.0版本,需要将pom.xml中的版本号换成你是用的版本:
我的改成2.12.12,同时添加spark相关依赖:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>untitled</artifactId>
<version>1.0-SNAPSHOT</version>
<inceptionYear>2008</inceptionYear>
<properties>
<scala.version>2.12.12</scala.version&g