Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I get sbt to gather all the jar files my code depends on into one place?

Tags:

jar

scala

sbt

I'm new to sbt. I want it to put all the dependency jar files as well as my jar file into one place. SBT will run the app, but I've got various dependencies scattered around and an .ivy folder full of things my jar file depends on indirectly.

So Is there a simple command to copy them all into a single place so I can distribute it to another machine?

like image 687
Tim Pigden Avatar asked Nov 02 '11 11:11

Tim Pigden


People also ask

How do we specify library dependencies in SBT?

The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.

Which is the correct way to add dependencies in SBT file?

If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.

Where are dependencies downloaded in SBT?

All new SBT versions (after 0.7. x ) by default put the downloaded JARS into the . ivy2 directory in your home directory. If you are using Linux, this is usually /home/<username>/.

How do I run a jar file in SBT?

Solution. Create a directory layout to match what SBT expects, then run sbt compile to compile your project, sbt run to run your project, and sbt package to package your project as a JAR file. Unlike Java, in Scala, the file's package name doesn't have to match the directory name.


2 Answers

There are many plugins you can use: sbt-assembly, sbt-proguard, sbt-onejar, xitrum-package etc.

See the list of SBT plugins.

like image 129
pr1001 Avatar answered Sep 21 '22 15:09

pr1001


Add the following line to your build.sbt file.

retrieveManaged := true 

This will gather the dependencies locally

like image 44
CatsLoveJazz Avatar answered Sep 21 '22 15:09

CatsLoveJazz