您的位置:首页 > 其它

Scala on Visual Studio Code

2016-09-08 14:40 651 查看

Download and install Scala

Download a scala installation package from here.

Then install it.

Linux

scala_package_name=$(ls scala*.tgz | sort -r | head -1)
tar -xzf $scala_package_name
mv ${scala_package_name%.*} scala


Configure system variables:

Linux

export SCALA_HOME=/opt/scala
PATH=%PATH%:$SCALA_HOME/bin


Windows

SCALA_HOME=C:\Program Files (x86)\scala
PATH=%SCALA_HOME%\bin;%PATH%


Test

scala


Output:

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_60).
Type in expressions for evaluation. Or try :help.

scala>

Configur a project in visual studio code

Open a project via File -> Open Folder...

Create a tasks.json file under the .vscode folder in the project folder.

Input below in the task.json file

// A task runner that runs a scala program
{
"version": "0.1.0",
"isShellCommand": true,
"args": [],
"showOutput": "always",
"echoCommand": true,
"suppressTaskName": true,
"windows": {
"command": "cmd",
"args": [
"/C",
"scala.bat"
]
},
"linux": {
"command": "sh",
"args": [
"scala"
]
},
"osx": {
"command": "sh",
"args": [
"scala"
]
},
"tasks": [
{
"taskName": "run",
"isBuildCommand": true,
"args": [
"${file}"
]
}
]
}

Note: I am using Windows, you need to change scala.bat to scala (I guess).

Linux

Test it

Create a file test.scala with code

object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}


press ctrl+shift+b

Output:

Hello, world!


Compile .scala to .jar

scalac -d test.jar D:\project\*
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: