zoukankan      html  css  js  c++  java
  • scala-sbt

    一、简单例子

    键入 sbt 回车即可进入命令行
    键入 exit 回车即可退出命令行

    在项目根目录新建 build.sbt 作为声明文件。
    在命令行键入 compile 即可编译项目
    如果键入 ~compile 则源码发生改变自动重新编译,回车可退出该模式。(其他命令亦可这样操作)

    在项目根目录下新建 src/main/scala 即可作为源码存放路径,
    在该路径下编写源码,如果在该目录下还有文件夹比如 example
    则源码中需要 package example 声明。

    编译之后键入 run 即可运行项目。
    键入 help 即可显示帮助信息。

    可以使用 set scalaVersion := "2.11.8" 声明scala版本为 2.11.8
    如果 build.sbt 声明文件发生改变,
    可以使用 reload 重新加载。

    声明依赖可以在 build.sbt 文件中写:
    libraryDependencies += "com.typesafe.play" %% "play-json" % "2.6.9"

    scala REPL 界面中,
    键入 :paste 可进入粘贴模式,
    键入 Ctrl+D 即可退出。

    二、目录结构

    src/
      main/
        resources/
           <files to include in main jar here>
        scala/
           <main Scala sources>
        scala-2.12/
           <main Scala 2.12 specific sources>
        java/
           <main Java sources>
      test/
        resources
           <files to include in test jar here>
        scala/
           <test Scala sources>
        scala-2.12/
           <test Scala 2.12 specific sources>
        java/
           <test Java sources>
    

    不在这个范围的目录或文件将被忽略,所有的隐藏文件将被忽略。

    在根目录下,所有以 .sbt 结尾的文件将被认为是编译设置文件,一般创建为 build.sbt

    所有编译产生的类文件、jars包、管理文件、缓存和文档将默认保存在 target 路径下。

    三、编译运行

    键入 sbt 可以启动 sbt 命令行,
    然后键入 compile 编译项目,
    接着键入 run 即可运行项目。

    如果想持续性编译测试项目可以使用 ~testQuick 命令。

    一些常用的命令

    命令 描述
    clean 删除所有生成的文件(在 target 文件夹中)
    compile 编译主要的源代码(在 `src/main/scala 和 src/main/java 目录下)
    test 编译并运行所有的测试
    console 进入 scala 解释器界面,:quit可以返回 sbt
    run 运行项目的主类
    package 将项目打包成一个 jar
    help 显示命令帮助信息
    reload 重新加载 build.sbt project/.scala project/.sbt 文件
    用于补全命令,按下两次根据提示可以显示所有命令
    <Ctrl+r> 在历史中搜索命令

    sbt shell also supports the following commands:

    ! Show history command help.
    !! Execute the previous command again.
    !: Show all previous commands.
    !:n Show the last n commands.
    !n Execute the command with index n, as shown by the !: command.
    !-n Execute the nth command before this one.
    !string Execute the most recent command starting with 'string.'
    !?string Execute the most recent command containing 'string.'

    如果想添加依赖关系,有两种方法:
    1、直接把 Jar 包丢进 lib 路径;
    2、在 build.sbt 文件里面声明。

  • 相关阅读:
    Codeforces 1045C Hyperspace Highways (看题解) 圆方树
    Codeforces 316E3 线段树 + 斐波那切数列 (看题解)
    Codeforces 803G Periodic RMQ Problem 线段树
    Codeforces 420D Cup Trick 平衡树
    Codeforces 295E Yaroslav and Points 线段树
    Codeforces 196E Opening Portals MST (看题解)
    Codeforces 653F Paper task SA
    Codeforces 542A Place Your Ad Here
    python基础 异常与返回
    mongodb 删除
  • 原文地址:https://www.cnblogs.com/amnotgcs/p/12944472.html
Copyright © 2011-2022 走看看