SBT project for java executable jar

无人久伴 提交于 2019-12-03 08:33:55

问题


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

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


回答1:


Use the assembly-sbt plugin (originally created by Coda Hale, now maintained by 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.:

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+).



来源:https://stackoverflow.com/questions/5864025/sbt-project-for-java-executable-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!