Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include an external jar file into the jar with package?

Tags:

sbt

My project has dependency on an external jar. I have created a directory lib and have copied the jar file into it. This is my build.sbt:

name := "approxstrmatch"  version := "1.0"  scalaVersion := "2.10.4"  unmanagedJars in Compile += file("lib/secondstring-20140729.jar")  libraryDependencies+="org.apache.spark"%%"spark-core"%"1.0.0"  resolvers += "AkkaRepository" at "http://repo.akka.io/releases/" 

When I run clean and package, the external jar file does not get included in the generated jar file. Why?

This is the project layout:

project/build.sbt lib/ src/..... 
like image 234
user3803714 Avatar asked Aug 04 '14 23:08

user3803714


People also ask

How do I create a jar file with an external library?

You can right-click on the project, click on export, type 'jar', choose 'Runnable JAR File Export'. There you have the option 'Extract required libraries into generated JAR'.


1 Answers

Try this

libraryDependencies += "com.acme.common" % "commonclass" % "1.0" from "file:///Users/bwong/git/perf-tools/commonclass/target/scala-2.11/commonclass_2.11-1.0.jar" 

I "sbt package" the common classproject and then just add that library dependency in my build.sbt in the dependent projects.

Thanks to http://flummox-engineering.blogspot.com/2014/06/sbt-use-jar-file-for-librarydependencies.html for this hack.

like image 152
Bernie Wong Avatar answered Sep 19 '22 13:09

Bernie Wong