Scala SBT:独立 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6026149/
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
Scala SBT: standalone jar
提问by dsg
The answer: Making stand-alone jar with Simple Build Toolseems like what I need, but it did not have enough information for me, so this is a followup.
答案:使用 Simple Build Tool 制作独立 jar似乎是我需要的,但它没有足够的信息给我,所以这是一个后续。
(1) How do I adapt the answer to my need? I don't understand what would need to be changed.
(1) 我如何根据我的需要调整答案?我不明白需要改变什么。
(2) What command do I run to create the standalone jar?
(2) 我运行什么命令来创建独立的 jar?
(3) Where can I find the jar after it has been created?
(3) jar 被创建后在哪里可以找到它?
What I've tried:
我试过的:
Pasting the code in the linked answer verbatim into my:
project/build/dsg.scalafile. The file now has aclass ForkRun(info: ProjectInfo) extends DefaultProject(info)(from before, used for running projects in a separate VM from SBT) and the new:
trait AssemblyProject extends BasicScalaProjectfrom the linked answer.
I also tried pasting the body (all
defsand thelazy valof theAssemblyProjectinto the body ofForkRun.
将链接答案中的代码逐字粘贴到我的:
project/build/dsg.scala文件中。该文件现在有一个class ForkRun(info: ProjectInfo) extends DefaultProject(info)(以前用于在与 SBT 不同的 VM 中运行项目)和新的:
trait AssemblyProject extends BasicScalaProject从链接的答案。
我也试过粘贴体(所有
defs和lazy val的AssemblyProject成体ForkRun。
To create a jarI ran packageat the SBT prompt and get:
要创建一个jar我package在 SBT 提示符下运行并得到:
[info] Packaging ./target/scala_2.8.1/dsg_2.8.1-1.0.jar ...
[info] Packaging complete.
So I tried running the dsg_2.8.1-1.0.jarfrom the shell via:
所以我尝试dsg_2.8.1-1.0.jar通过以下方式从 shell运行:
java -jar dsg_2.8.1-1.0.jar
But I get:
但我得到:
Failed to load Main-Class manifest attribute from
dsg_2.8.1-1.0.jar
Could this be caused by having multiple entry points into my project? I select from a list when I execute runfrom the SBT prompt. Perhaps I need to specify the default when creating the package?
这可能是因为我的项目有多个入口点吗?当我run从 SBT 提示执行时,我从列表中进行选择。也许我需要在创建包时指定默认值?
采纳答案by Janx
Here's a writeup I did on one way to make an executable jar with SBT:
这是我用 SBT 制作可执行 jar 的一种方法的一篇文章:
http://janxspirit.blogspot.com/2011/01/create-executable-scala-jar-with-sbt.html
http://janxspirit.blogspot.com/2011/01/create-executable-scala-jar-with-sbt.html

