How to package a Scala project to a .jar with sbt?

How to package a Scala project to a .jar file with sbt? Manually packaging the .class files are fine but too tedious.

asked May 29, 2014 by Eric Z Ma (44,280 points)

1 Answer

 
Best answer

A jar of just the project classes

The command:

sbt package

will produces the main artifact as a jar into target/scala-2.x.y/project_name_2.x.y-zz.jar.

Continuously building the package:

sbt ~package

Standalone jar with all dependencies

If you want to build a standalone executable jar with dependencies, you may use the sbt-assembly plugin. And then build it by

sbt assembly

The standalone will be in target/project_name-assembly-x.y.jar.

You can run it by

java -jar project_name-assembly-x.y.jar [class.with.main.function]
answered May 29, 2014 by Eric Z Ma (44,280 points)
edited May 29, 2014 by Eric Z Ma

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...