Preface
I haven’t written a blog for a long time. Let’s write one for the time being. It’s not for any other reason, but as I write more and more blogs in the past, I feel more and more that a professional blog needs some systematic or refined things. I wrote it before Most of the content is just a running account and lacks depth. It only has breadth, which is far from enough.
Okay, no more gossip. This article mainly records the construction of the IDEA Scala environment.
Installing Scala on Windows
- Download the Scala installation package
https://www.scala-lang.org/download/
Select the required version. https://www.scala-lang.org/download/2.12.17.html
Download the zip package.
Unzip the zip package. We cd to the corresponding directory and you can see that scala.bat
it is already an executable file. At this point we can configure environment variables to make use more convenient.
- Configure Scala path
First configureSCALA_HOME
D:\develop\scala\apps\scala-2.11.12
Then configure it into path. ( %SCALA_HOME%\bin
)
- Test:
scala -v
Enter any directory and executescala -v
. You can see the results as shown below.
IDEA settings Scala plug-in & project settings Scala
- Install scala plugin
setting -> Plugins -> Scala
- Create a simple Maven project. And add the following dependency packages.
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>scala-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<scala.binary.version>2.11</scala.binary.version>
<scala.version>2.11.12</scala.version>
</properties>
<dependencies>
<!-- Scala Library, provided by Flink as well. -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
<!-- <scope>provided</scope>-->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<!-- 声明绑定到maven的compile阶段 -->
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The main ones are a scala-library. And a scala IDEA plug-in, which allows you to create Scala type files.
- Add local scala address
Project Structure --> Global Libraries -> 添加
- After joining, you can find that IDEA can load scala Library.
Demo Helloword
- Create the scala folder and set it to
source root
.
- Create the corresponding package and set
package com.yanxml.scala.quick
object HelloWorld {
def main(args: Array[String]): Unit = {
System.out.print("Hello World")
}
}
Reference
[1] IDEA 2020.3.X Detailed tutorial on creating scala environment
[2] How to build the Scala development environment of Intellij idea
[4] spark-Build scala programming environment in IDEA