scala 我如何让 sbt 将我的代码依赖的所有 jar 文件收集到一个地方?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7979336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how do I get sbt to gather all the jar files my code depends on into one place?
提问by Tim Pigden
I'm new to sbt. I want it to put all the dependency jarfiles as well as my jar file into one place. SBT will run the app, but I've got various dependencies scattered around and an .ivyfolder full of things my jar file depends on indirectly.
我是sbt 的新手。我希望它将所有依赖jar文件以及我的 jar 文件放在一个地方。SBT 将运行该应用程序,但我有各种各样的依赖项分散在一个.ivy文件夹中,其中包含我的 jar 文件间接依赖的内容。
So Is there a simple command to copy them all into a single place so I can distribute it to another machine?
那么是否有一个简单的命令可以将它们全部复制到一个地方,以便我可以将其分发到另一台机器?
采纳答案by pr1001
There are many plugins you can use: sbt-assembly, sbt-proguard, sbt-onejar, xitrum-packageetc.
您可以使用许多插件:sbt-assembly、sbt-proguard、sbt-onejar、xitrum-package等。
See the list of SBT plugins.
请参阅SBT 插件列表。
回答by CatsLoveJazz
Add the following line to your build.sbtfile.
将以下行添加到您的build.sbt文件中。
retrieveManaged := true
This will gather the dependencies locally
这将在本地收集依赖项
回答by torrens
Create a task in your build file like this:
在您的构建文件中创建一个任务,如下所示:
lazy val copyDependencies = TaskKey[Unit]("pack")
def copyDepTask = copyDependencies <<= (update, crossTarget, scalaVersion) map {
(updateReport, out, scalaVer) =>
updateReport.allFiles foreach {
srcPath =>
val destPath = out / "lib" / srcPath.getName
IO.copyFile(srcPath, destPath, preserveLastModified = true)
}
}
Add the Task to a Project like this:
将任务添加到项目中,如下所示:
lazy val HubSensors =
Project("HubSensors", file("HubSensors"), settings = shared ++ Seq(
copyDepTask,
resolvers ++= Seq(novusRels),
libraryDependencies ++= Seq(
jodatime
)
)) dependsOn(HubCameraVision, JamServiceProxy, HubDAL)
In the SBT console type:
在 SBT 控制台中键入:
project [Project Name]
pack
回答by leo
Try sbt-pack plugin https://github.com/xerial/sbt-pack, which collects all dependent jars in target/pack folder and also generates launch scripts.
尝试 sbt-pack 插件https://github.com/xerial/sbt-pack,它收集 target/pack 文件夹中的所有依赖 jar 并生成启动脚本。
回答by Adrien Aubel
You could also try SBT Native Packager: https://github.com/sbt/sbt-native-packager(sbt 0.7+)
你也可以试试 SBT Native Packager:https: //github.com/sbt/sbt-native-packager(sbt 0.7+)
This is still a WIP but will be used in Play Framework 2.2 in the coming weeks. With this, you can create standalone ZIP files, Debian packages (DEB), Windows installation packages (MSI), DMG, RPM, and so on.
这仍然是一个 WIP,但将在未来几周内用于 Play Framework 2.2。有了它,您可以创建独立的 ZIP 文件、Debian 包 (DEB)、Windows 安装包 (MSI)、DMG、RPM 等。
回答by bstpierre
The SBT docs have a list of "One Jar Plugins":
SBT 文档有一个“One Jar Plugins”列表:
- sbt-assembly: https://github.com/sbt/sbt-assembly
- xsbt-proguard-plugin: https://github.com/adamw/xsbt-proguard-plugin
- sbt-deploy: https://github.com/reaktor/sbt-deploy
- sbt-appbundle (os x standalone): https://github.com/sbt/sbt-appbundle
- sbt-onejar (Packages your project using One-JAR?): https://github.com/sbt/sbt-onejar
- sbt-assembly:https: //github.com/sbt/sbt-assembly
- xsbt-proguard-plugin: https://github.com/adamw/xsbt-proguard-plugin
- sbt-deploy: https://github.com/reaktor/sbt-deploy
- sbt-appbundle (os x 独立): https://github.com/sbt/sbt-appbundle
- sbt-onejar(使用 One-JAR 打包您的项目?):https: //github.com/sbt/sbt-onejar
回答by anvie
May you looking for this sbt plugin: https://github.com/anvie/sbt-onedir-plugin
可能你正在寻找这个 sbt 插件:https: //github.com/anvie/sbt-onedir-plugin

