Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt: How can I add a local filesystem jar to my project?

I have a library compiled to a jar (not an sbt project, just the jar file) that's not available on a repository.

Is there a simple way to add a reference to the jar in the filesystem/project directly?

like image 577
Jeff Axelrod Avatar asked Oct 11 '11 21:10

Jeff Axelrod


People also ask

Where are SBT jars stored?

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>/.

What is Ivy in SBT?

Apache Ivy is a transitive package manager. It is a sub-project of the Apache Ant project, with which Ivy works to resolve project dependencies. An external XML file defines project dependencies and lists the resources necessary to build a project.

How do I publish to local SBT?

To use publishing, you need to specify the repository to publish to and the credentials to use. Once these are set up, you can run publish . The publishLocal action is used to publish your project to your Ivy local file repository, which is usually located at $HOME/. ivy2/local/ .


2 Answers

You can put the jar in your project's lib folder (create it if it doesn't exist), it will then appear on your project's unmanaged-classpath.

To publish a jar file locally, if you have an sbt project that produces the jar, it should be as simple as invoking "publish-local" to publish the jar to your local ivy repository so that you can use that jar in another one of your projects (on the same computer).

like image 152
Fred Dubois Avatar answered Oct 06 '22 20:10

Fred Dubois


Your SBT project should be structured like this:

README.md build.sbt project/ src/ target/ 

Create a lib/ directory to add a JAR file (e.g. spark-daria_2.11-0.2.0.jar) to the project:

README.md build.sbt lib/   spark-daria_2.11-0.2.0.jar project/ src/ target/ 

The location of the lib/ directory should line-up with the output of the sbt "show unmanagedBase" command.

Refresh the project in your IDE and import the code just like you would import an external dependency.

import com.github.mrpowers.spark.daria.sql.DataFrameValidator 
like image 32
Powers Avatar answered Oct 06 '22 19:10

Powers