I'm trying to add jar files to an sbt project, but I can't figure out where to store them. The sbt docs say "Just drop them in the lib folder, and you're good!", but don't give any information about where to actually put this lib folder. Does the lib folder go under src? at the top level hierarchy where the src folder is located? I'm really not sure, and would appreciate some help.
Asked
Active
Viewed 1.1k times
20
-
For a multi-module `sbt` project see https://stackoverflow.com/questions/23919388/how-to-inherit-unmanaged-dependencies-in-submodules-in-sbt – SemanticBeeng Aug 31 '18 at 08:04
3 Answers
29
According to http://alvinalexander.com/scala/how-to-create-sbt-project-directory-structure-scala , lib should be a subdirectory of your project directory. I just tried it, it works.
.
|-- build.sbt
|-- lib
|-- project
|-- src
| |-- main
| | |-- java
| | |-- resources
| | |-- scala
| |-- test
| |-- java
| |-- resources
| |-- scala
|-- target

foghorn
- 997
- 2
- 10
- 16
-
Thanks for adding this answer. I found the answer somewhere else, but I guess I forgot about this question. Hopefully it's useful for anyone else searching for this. – redeagle47 Oct 27 '15 at 21:43
-
1Does this apply to any third party jars including java application jars built using maven/gradle? Does SBT look for third party jars first in the local lib folder or I need to specify a resolver for it? – Andy Dufresne Jan 29 '17 at 04:39
0
I would imagine so, at the top of the file hierarchy. Additionally, if you use a modern IDE, such as Eclipse, InteliJ and more, you can do this by simply following these steps:
- Right click on [Project Name] in project file tree
- Properties
- Java Build Paths --> Libraries
- Add External Jar
If you need more help just say so.
On the former option (where you drag the jar files into the project), you would do the following:
- In the root of the project, where
src
is located, create a new file calledlib
or whatever and drag thejar
files into it. After this, you will need to re-configure the build path or if you are using a modern IDE you can simply right-click on thelib
file and selectBuild Path --> Add to Build Path
.
0
If you have multi-module project you should:
- add lib to module dir (not to root). E.g., if you have module
core
, you should add jar tocore/lib
. - remove explicit dependency for specified jar in your build.sbt (or in another place). E.g., remove
libraryDependencies += <your jar in lib>

o_O
- 341
- 3
- 14

Mikhail Ionkin
- 568
- 4
- 20