BAR
BAR

Reputation: 17061

Include Dependencies in JAR using SBT package

Apparently project dependencies are not being packaged into the jar generated by:

sbt package

How can dependencies be included?

Upvotes: 17

Views: 22304

Answers (2)

prayagupadhyay
prayagupadhyay

Reputation: 31192

Well, I use sbt-assembly plugin to create jar with dependencies,

(1) add sbt-assembly to projects/assembly.sbt

echo 'addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.8")' > project/assembly.sbt

(2) run sbt clean assembly to build the jar. It will create ${name}-assembly-${version}.jar in target/scala-${scalaVersion}

(3) Only in case you get infamous de-duplicate error, use assemblyMergeStrategy as described in here

Upvotes: 22

djsumdog
djsumdog

Reputation: 2710

There's a project called onejar that will package a project and all its dependencies into a single jar file. There is an SBT plugin as well:

https://github.com/sbt/sbt-onejar

However if you're just looking to create a standard package (deb, rpm, etc.) there is sbt-native-packager:

https://github.com/sbt/sbt-native-packager

It can place all your dependencies into a Linux package and add the appropriate wrappers to load all your dependencies and start your program or service.

Upvotes: 8

Related Questions