1.安装相关插件
这里由于在plugins里未搜到scala,是离线安装的scala插件
可以在改地址下载对应版本https://plugins.jetbrains.com/plugin/1347-scala/versions/stable
2.在pom文件中添加相关依赖
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.12.11</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.12.11</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-reflect</artifactId>
<version>2.12.11</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.12</artifactId>
<version>2.4.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Java Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- Scala Compiler -->
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.12.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
3 编写scala代码
4 可能遇到的错误
Exception in thread “main“ java.lang.NoSuchMethodError: scala.Product.
i
n
i
t
init
init(Lscala/Product;)V
原因:
scala版本与当前spark版本不一致,之前scala版本用的是2.11,而spark-core_2.12,两者不一致,在运行scala代码的时候报改错
解决:将scala改成和spark的一致版本即可
5 另一种方式
在第一步后,右击项目点击add framework support
找到scala并应用即可编写scala代码