How do I run an sbt main class from the shell as normal command-line program?

前端 未结 4 1697
轻奢々
轻奢々 2020-12-02 15:00

How can I run an sbt app from the shell, so that I can run my app as a normal command-line program (as if run directly via scala but without having to set up an

4条回答
  •  借酒劲吻你
    2020-12-02 15:06

    The start-script SBT plugin is now at:

    https://github.com/sbt/sbt-start-script

    It requires a few steps to set up and generates scripts that do not work on OS X, but that can be easily fixed if you're on that platform (see below).

    Setup

    1. Install greadlink (OS X only):

      a) brew install coreutils

      b) map readlink to the new function (greadlink) by adding these lines to ~/.bashrc:

      function readlink() { greadlink "$@"; }

      export -f readlink`

    2. Add start-script plugin to ~/.sbt/plugins/build.sbt:

      addSbtPlugin("com.typesafe.sbt" % "sbt-start-script" % "0.8.0")

    3. Add start-script task to current project:

      $ sbt add-start-script-tasks # execute from directory where build.sbt resides

    4. Add start-script support to current build.sbt:

      import com.typesafe.sbt.SbtStartScript

      seq(SbtStartScript.startScriptForClassesSettings: _*)

    Note the blank line in between statements (de rigueur for SBT build files).

    Generate Start Script

    Then, whenever you want to create a script to start your app like sbt run-main, but without sbt, execute:

    $ sbt start-script
    

    Run

    target/start mypackage.MyMainClass
    

提交回复
热议问题