前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Scala on Visual Studio Code

Scala on Visual Studio Code

作者头像
绿巨人
发布2018-05-16 17:45:51
3K0
发布2018-05-16 17:45:51
举报
文章被收录于专栏:绿巨人专栏绿巨人专栏

Download and install Scala

Download a scala installation package from here. Then install it.

  • Linux
代码语言:javascript
复制
scala_package_name=$(ls scala*.tgz | sort -r | head -1) 
tar -xzf $scala_package_name 
mv ${scala_package_name%.*} scala

Configure system variables:

  • Linux
代码语言:javascript
复制
 export SCALA_HOME=/opt/scala 
PATH=%PATH%:$SCALA_HOME/bin
  • Windows
代码语言:javascript
复制
 SCALA_HOME=C:\Program Files (x86)\scala 
PATH=%SCALA_HOME%\bin;%PATH%

Test

代码语言:javascript
复制
scala
  • Output:
代码语言:javascript
复制
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
代码语言:javascript
复制
// 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
代码语言:javascript
复制
object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}
  • press ctrl+shift+b
  • Output: Hello, world!

Compile .scala to .jar

代码语言:javascript
复制
scalac -d test.jar D:\project\*
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-09-08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Download and install Scala
    • Configure system variables:
      • Test
      • Configur a project in visual studio code
      • Linux
      • Test it
        • Compile .scala to .jar
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档