简体   繁体   中英

How to use java libraries with scala using sbt?

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?

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM