Scala SBT: standalone jar

2019-03-11 02:44发布

问题:

The answer: Making stand-alone jar with Simple Build Tool seems like what I need, but it did not have enough information for me, so this is a followup.

(1) How do I adapt the answer to my need? I don't understand what would need to be changed.

(2) What command do I run to create the standalone jar?

(3) Where can I find the jar after it has been created?


What I've tried:

  • Pasting the code in the linked answer verbatim into my: project/build/dsg.scala file. The file now has a

    class ForkRun(info: ProjectInfo) extends DefaultProject(info)

    (from before, used for running projects in a separate VM from SBT) and the new:

    trait AssemblyProject extends BasicScalaProject

    from the linked answer.

  • I also tried pasting the body (all defs and the lazy val of the AssemblyProject into the body of ForkRun.

To create a jar I ran package at the SBT prompt and get:

[info] Packaging ./target/scala_2.8.1/dsg_2.8.1-1.0.jar ...
[info] Packaging complete.

So I tried running the dsg_2.8.1-1.0.jar from the shell via:

java -jar dsg_2.8.1-1.0.jar 

But I get:

Failed to load Main-Class manifest attribute from
dsg_2.8.1-1.0.jar

Could this be caused by having multiple entry points into my project? I select from a list when I execute run from the SBT prompt. Perhaps I need to specify the default when creating the package?

回答1:

Here's a writeup I did on one way to make an executable jar with SBT:

http://janxspirit.blogspot.com/2011/01/create-executable-scala-jar-with-sbt.html



回答2:

sbt-assembly is a sbt plugin to create a standalone jar of Scala sbt project with all of its dependencies.

Refer this post for more details with an example.