1

So, I have a project written in Scala for Spark. The current sbt file looks like this.

name := "MyProgram"

version := "1.0"

scalaVersion := "2.10.4"

libraryDependencies += "org.apache.spark" %% "spark-core" % "1.1.0"

Say, I want to use external java libraries, and all those libraries are in a directory lib. How should I modify the sbt file to include those libraries?

1
  • If those external libraries are available on Maven or other publicly accessible repos you should add them as dependencies to your build.sbt. Commented May 31, 2015 at 13:07

2 Answers 2

5

Sbt should auto include all jars inside the lib folder.

Dependencies that are just floating around in the lib folder (rather than declared in your build.sbt file) are called unmanaged dependencies

Sign up to request clarification or add additional context in comments.

6 Comments

My current source code files are in folder src\main\scala. Where should I put the lib folder?
The lib folder belongs at the top level of your project. Alongside src
Great. And If I want to run the program on an another computer (not where I compiled), where should I place those lib files?
Same folder. The link I posted outlines how unmanaged dependencies work
Dominic answer is correct. However, that works as long as you are running everything from the same machine you are compiling. If you want to run on different machine then you need to package your project. You can try using a uber/fat jar plugin, like sbt-assembly. Otherwise, you can use the package task and then make sure all dependencies (managed and unmanaged) are included in the Java classpath.
|
0

As a use case example of unmanaged dependencies (as mentioned by Dominic) add these patterns in build.sbt,

unmanagedBase <<= baseDirectory(_ / "./java-libs")

unmanagedClasspath in Compile +=
    file(System.getenv("EXTRA_LIBS_HOME")) / "java-libs/package.jar"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.