How to run jar generated by package (possibly with other jars under lib)?

You can use the sbt plugin sbt-assembly:

sbt-assembly >= 0.12.0 with sbt >= 0.13.6

Since sbt-assembly is now an auto plugin, it is sufficient to add project/assembly.sbt to your sbt project:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5")

sbt-assembly 0.11

Add project/assembly.sbt to your sbt project:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")

Add assembly.sbt as well:

import AssemblyKeys._ // put this at the top of the file

assemblySettings

Usage

This gives you another sbt command:

sbt assembly

which produces a “fat jar” (which includes all dependencies, including the Scala libraries).

Now you can start your program

java -cp …/package-assembly.jar

so you only need a Java installation and the “fat jar”.

Leave a Comment