Deploy Scala binaries without dependencies

后端 未结 1 1254
不思量自难忘°
不思量自难忘° 2021-02-04 14:01

Is there an easy way to copy a Scala Jar (~1MB) to a server and then have SBT pull in the dependencies (~40MB) it needs and run it?

I\'ve seen sbt-onejar and sbt-assembl

1条回答
  •  深忆病人
    2021-02-04 14:15

    Deploy your .jar to a repository (I use Artifactory, but I think you can publish via scp to a filesystem) that your servers can access. Create an empty sbt project that has a single dependency on your app's .jar file. You servers can pull and sbt update this empty project to download the jars to the server in a way that takes advantage of the local Ivy cache and is very bandwidth friendly. Then it's just a matter of getting the right classpath to launch your app.

    One thing you have to watch out for is to make sure that sbt will actually update your dependencies. There's been some conversation about this on SBT's mailing list.

    Options for launching the app (in order of increasing cleverness) are:

    • Just run sbt run
    • Use sbt-onejar or sbt-assembly to create a single .jar and run java -jar to run it
    • Write some sbt scripts to build the classpath, and use that to launch the app directly out of the Ivy cache. I seem to recall seeing a script to do that recently on SO, but can't find it at the moment. You can find a script that does this in this SO answer, or (as you suggested below) use the xsbt-start-script-plugin.

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