SBT project for java executable jar

后端 未结 1 1574
梦如初夏
梦如初夏 2021-02-04 02:16

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-m

相关标签:
1条回答
  • 2021-02-04 02:48

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

    0 讨论(0)
提交回复
热议问题