告诉 SBT 收集我所有的依赖项 [英] Tell SBT to collect all my dependencies together
问题描述
在构建 Web 应用程序时,SBT 能够将我所有的 jar 依赖项收集到 WAR 文件中.
When building a web application SBT is able to collect all my jar dependencies into the WAR file.
这是否可以让 SBT 将我在非 Web 应用程序中依赖的所有 jar 文件放到一个目录中,以便我在运行应用程序时可以轻松地将它们放到我的类路径中?
Is this possible to have SBT put all the jars I depend on in my non-web application into a directory so I can easily put them onto my class path when running the app?
推荐答案
是的,你可以在你的项目定义类中放入这样的东西:
Yes, you can put something like this in your project definition class:
val libraryJarPath = outputPath / "lib"
def collectJarsTask = {
val jars = mainDependencies.libraries +++ mainDependencies.scalaJars
FileUtilities.copyFlat(jars.get, libraryJarPath, log)
}
lazy val collectJars = task { collectJarsTask; None } dependsOn(compile)
并通过 SBT 控制台中的 collect-jars
运行任务.这会将 scala-library.jar 和用于编译的 jar 复制到与 classes
目录相同的目录中名为 lib
的目录中.
and run the task via collect-jars
in your SBT console. This will copy the scala-library.jar and the jars used for compilation in a directory called lib
in the same directory as your classes
directory.
这篇关于告诉 SBT 收集我所有的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!