我的目录结构是这样设置的。
src/main/scala/main/Main.scala
src/main/scala/scripts/MainScript.scala
该脚本是将运行的后台作业。
我用过
sbt-assembly
之前将主文件打包到要部署的 jar 中,但我不确定如何使用 sbt-assembly
创建两个单独的 jar。或 sbt-native-packager
.我将如何去做,解决这个问题的最佳方法是什么?我会做类似的事情。
java -jar main.jar $PORT
java -jar scriptMain.jar
最佳答案
仅使用 native-packager 解决此问题的一种方法如下。
src/main/scala
中mainClass in Compile := Some("foo.bar.Main")
应该默认运行 src/universal/bin
你想提供的。这些脚本可以调用native-packager生成的主脚本and set the -main
要调用的类的参数。 现在您有一个具有以下结构的输出包(例如 zip、rpm、deb)。假设您的应用名为 我的应用 并且您提供给其他名为 的 bin 脚本otherApp1 / otherApp2
lib/ (jars live here)
conf/ (configuration files here, if any)
bin/
myApp
otherApp1
otherApp2
不幸的是,我没有脚本示例(我的 bash-foo 对 SO 上的即时魔法还不够好)。最后,脚本(otherApp1、otherApp2)应该只将它们接收到的参数传递给本地打包程序脚本(myApp)。
有an issue #633它提供了一种自动方式来生成这样的脚本。
希望有帮助,
向木
关于scala - 使用 sbt 运行多个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36362418/