问题
I've created an IntelliJ Idea SBT Scala project like Heiko Seeberger's article describes.
I'd like to add a Jar library (joda-time) to use in this project. How to do this? Simply putting them into project's /lib does not help. If I right-click "External libraries" in Idea's project tree, "New >" is greyed.
回答1:
In the IntelliJ Idea window of your project, got to File >> Project structure >> Libraries. After clicking that Libraries option, two panes will show up. At the top of the left-most pane, click the green "+" button.
回答2:
The better way to do it is to add your unmanaged dependencies to your build.sbt and refrain from leaving part of your dependency management to your IDE.
Refer to http://www.scala-sbt.org/release/docs/Library-Management.html for details on how to define your unmanagedBase and unmanagedJars tasks.
回答3:
Just Declare this in build.sbt
unmanagedJars in Compile += file(Path.userHome+"/Your-Jar-Path/Full-Jar-Name.jar")
and required jar will appear in External Library>unmanaged-jars>Full-Jar-Name.jar. This will also change if the jar file(in the provided path) is modified.
回答4:
In Intellij Idea:
- File > Project Structure > Libraries
In Netbeans:
- File > Project Properties > Libraries
In Eclipse:
- Right click the project > Properties > Java Build Path > Libraries
回答5:
For a multi-module SBT project (Intellij 2017.3.4, Scala 12.2.4, sbt 1.1.1), the accepted solution only worked until restart or a project refresh. Indeed, "Project Settings-> Modules -> Dependencies", then "+" and "JARs or directories" gives a warning "Module X is imported from Sbt. Any changes made in its configuration may be lost after reimporting".
Possible workaround:
The suggestion by @zero worked for me as follows:
- Put the JAR(s) into the project's
lib
directory. - In
build.sbt
, insidelazy var baseSettings = Seq( ... )
add the lineunmanagedJars in Compile += file("YourPath/ProjectBla/lib/controlsfx-8.40.14.jar")
. Still no luck? In the SBT tool window, in a module's sbt settings under unmanagedBase, unmanagedSourceDirectories (and the like) try calling the pop-up commands "Show value" and "Inspect" a few times. Somehow, it might work.
From Eugene Yokota's answer to How can I add unmanaged JARs in sbt-assembly to the final fat JAR? another option (which I didn't try) is to add an individual
lib
directory to each required module.
Hopefully, these steps will solve the problem or at least help debugging.
回答6:
Create a lib directory in your project root path, paste your JARs in there, run sbt reload, close the project and open it again. Works for me in IntelliJ 2018.2.4 and SBT 1.0
来源:https://stackoverflow.com/questions/3796004/how-to-add-jar-libraries-to-an-intellij-idea-sbt-scala-project