Java可执行jar的SBT项目 [英] SBT project for java executable jar

查看:168
本文介绍了Java可执行jar的SBT项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

它需要捆绑scala-library.jar并设置主方法的清单.

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

推荐答案

使用assembly-sbt插件(最初由Coda Hale创建,现在由 https://github.com/sbt/sbt -组装

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

一旦将其添加到项目中,它将构建一个可以通过java -jar projectName-assembly.jar执行的所谓的"fatjar".它将自动检测您的主要方法-如果源中有多个方法,则可以通过设置mainclass来明确设置要使用的方法,例如:

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")

注意:我将这个答案编辑为最新版本的SBT(0.11 +).

这篇关于Java可执行jar的SBT项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆