scala java可执行jar的SBT项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5864025/
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 02:59:21  来源:igfitidea点击:

SBT project for java executable jar

scalaexecutable-jarsbt

提问by Synesso

What is the best way to set the target package for an SBT project to be an executable jar file?

将 SBT 项目的目标包设置为可执行 jar 文件的最佳方法是什么?

It would need to bundle scala-library.jar and set the manifest for main-method.

它需要捆绑 scala-library.jar 并设置 main-method 的清单。

回答by Thomas Lockney

Use the assembly-sbt plugin (originally created by Coda Hale, now maintained by Eugene Yokota): https://github.com/sbt/sbt-assembly

使用 assembly-sbt 插件(最初由 Coda Hale 创建,现在由Eugene Yokota维护):https: //github.com/sbt/sbt-assembly

Once you add this to your project it will build a so-called "fatjar" which is executable via java -jar projectName-assembly.jar. It will autodetect your main method -- if there is more than one in your source, you can explicitly set which one to use by setting mainclass, e.g.:

一旦你将它添加到你的项目中,它就会构建一个所谓的“fatjar”,它可以通过java -jar projectName-assembly.jar. 它将自动检测您的主要方法——如果您的源中有多个方法,您可以通过 setting 明确设置要使用的方法mainclass,例如:

mainClass in assembly := Some("com.package.ClassNameWithMain")

Note: I edited this answer to be up-to-date with the current release of SBT (0.11+).

注意:我编辑了这个答案以与当前版本的 SBT (0.11+) 保持同步。