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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 03:01:12  来源:igfitidea点击:

Scala SBT: standalone jar

scalapackageexecutable-jarsbt

提问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 a

    class ForkRun(info: ProjectInfo) extends DefaultProject(info)

    (from before, used for running projects in a separate VM from SBT) and the new:

    trait AssemblyProject extends BasicScalaProject

    from the linked answer.

  • I also tried pasting the body (all defsand the lazy valof the AssemblyProjectinto the body of ForkRun.

  • 将链接答案中的代码逐字粘贴到我的:project/build/dsg.scala文件中。该文件现在有一个

    class ForkRun(info: ProjectInfo) extends DefaultProject(info)

    (以前用于在与 SBT 不同的 VM 中运行项目)和新的:

    trait AssemblyProject extends BasicScalaProject

    从链接的答案。

  • 我也试过粘贴体(所有defslazy valAssemblyProject成体ForkRun

To create a jarI ran packageat the SBT prompt and get:

要创建一个jarpackage在 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

回答by prabeesh

sbt-assemblyis a sbt plugin to create a standalone jar of Scala sbt project with all of its dependencies.

sbt-assembly是一个 sbt 插件,用于创建 Scala sbt 项目的独立 jar 及其所有依赖项。

Refer this postfor more details with an example.

有关示例的更多详细信息,请参阅此帖子