zoukankan      html  css  js  c++  java
  • Scala on Visual Studio Code

    [comment]: # Scala on Visual Studio Code

    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%in;%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*
    
  • 相关阅读:
    关于Python3.7和Python3.6中元组类型数据内存存储问题
    PHP中的语法特点小结
    PHP中的魔术常量
    Python02期(北京)课程笔记索引
    初识python
    Django项目功能执行逻辑流程图之用户页面信息展示和添加
    Django中的Model模型
    浅谈web开发以及django的安装和入门
    对前面知识的重新理解
    8月26号
  • 原文地址:https://www.cnblogs.com/steven-yang/p/5852988.html
Copyright © 2011-2022 走看看