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

JarRepositorySbt

Jar Problem Overview


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?

Jar Solutions


Solution 1 - Jar

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

Solution 2 - Jar

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

Solution 3 - Jar

If you have multi-module project you should:

  1. add lib to module dir (not to root). E.g., if you have module core, you should add jar to core/lib.
  2. remove explicit dependency for specified jar in your build.sbt (or in another place). E.g., remove libraryDependencies += <your jar in lib>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJeff AxelrodView Question on Stackoverflow
Solution 1 - JarFred DuboisView Answer on Stackoverflow
Solution 2 - JarPowersView Answer on Stackoverflow
Solution 3 - JarMikhail IonkinView Answer on Stackoverflow