Table of contents
2. Configure environment variables
Four ideas to write scala files
2. Use idea to create a scala project
3. Use idea to create a maven project to develop scala
Once downloaded and unzipped
Go to the official website to choose the appropriate version to download.
Official website address https://www.scala-lang.org/download/all.html
This article chose version 2.12.11
After downloading, unzip it to a certain path
2. Configure environment variables
Open the terminal and enter: (Of course, it doesn’t have to be this file. You can also open the file configuration you commonly use to configure environment variables. They are all the same. For friends who configure environment variables for the first time, this will be a new file)
vim .bash_profile
Enter the file to add content
SCALA_HOME here is the absolute path to the installation package you just decompressed.
#SCALA
export SCALA_HOME=/Users/yihongda/scala-2.12.11
export PATH=$PATH:$SCALA_HOME/bin
After typing: wq save
Source it after it comes out
source .bash_profile
Three tests scala
Terminal input
scala -version
If the version information appears, the installation is successful.
Enter scala in the terminal and write a few more sentences to see if they are correct.
Four ideas to write scala files
Friends who are using idea to write scala for the first time may need to install the plug-in first.
Because IDEA does not support Scala development by default, you need to install the Scala plug-in.
1. Install the scala plug-in
Open idea -> idea in the upper left corner -> setting -> Plugins -> search for scala -> click to install
After the download is complete, restart idea.
After restarting--"file in the upper left corner--"project structure--"Global Libraries--"there is a + sign in the middle area--"Select Scala SDK
After selection, the following pop-up box will appear. Select browse to find your scala installation directory.
Click OK and the plug-in is installed.
Expansion: Of course, you can also download the plug-in package yourself. The steps are briefly described below:
插件离线安装步骤
(1)建议将该插件scala-intellij-bin-2017.2.6.zip文件,放到Scala的安装目录D:\Tools\scala-2.12.11下,方便管理。
(2)打开IDEA,在左上角找到File->在下拉菜单中点击Setting... ->点击Plugins->点击右下角Install plugin from disk…,找到插件存储路径D:\Tools\scala-2.12.11\scala-intellij-bin-2017.2.6.zip,最后点击ok。
2. Use idea to create a scala project
Enter idea and click new project——》Select scala——》Select IDEA
Name the project and select the storage location. The defaults for jdk and scala SDK are fine. Finish
Just like java, create a package first
Right click on src——》new——”Package——”Name
Right-click on the newly created package -> new -> select Scala Class -> select Object and name it
Write a simple program to run
package demo01
object Demo {
def main(args: Array[String]): Unit = {
printf("hello scala");
}
}
3. Use idea to create a maven project to develop scala
Click on file——》Click on new project——>Select Maven——>Select quickstart framework
Name your project
Select your maven directory and configuration file
After the project is created, create the scala directory in the src/main directory
By default, Maven does not support Scala development and needs to introduce the Scala framework.
On the scala project, right click -> Add Framework Support... -> select Scala -> click OK
Note : If it is the first time to introduce the framework, Use libary cannot be seen. You need to select your Scala installation directory, and then the tool will automatically recognize it and user libary will be displayed.
File in the upper left corner——"project structure——"module——"click scala——"then click sources above——"then you will find that the folder color is consistent with java
Now create a package in the scala folder -> Create scala file
Select object
Write a simple statement to output the test