Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can sbt-native-packager generate multiple start scripts for one project?

I'm currently using sbt-native-packager to generate a start script for my scala application. I'm using packageArchetype.java_application. I create the script in sbt:

sbt clean myproject/stage

and then "install" the application by copying the created lib and bin directories to the installation directory. I'm not distributing it to anyone, so I'm not creating an executable jar or tarball or anything like that. I'm just compiling my classes, and putting my jar and all the library dependency jars in one place so the start script can execute.

Now I want to add a second main class to my application, so I want a second start script to appear in target/universal/stage/bin when I run sbt stage. I expect it will be the same script but with a different name and app_mainclass set to the different class. How would I do this?

like image 591
Adam Mackler Avatar asked Jul 31 '14 13:07

Adam Mackler


1 Answers

The sbt-native-packager generated script allows you to pass in a -main argument to specify the main class you want to run. Here's what I do for a project named foo:

Create a run.sh script with whatever common options you want that calls the sbt-native-packager generated script:

#!/bin/bash

./target/universal/stage/bin/foo -main "$@"

Then I create a separate script for each main class I want to run. For example first.sh:

#!/bin/bash

export JAVA_OPTS="-Xms512m -Xmx512m"

./run.sh com.example.FirstApp -- "$@"

and second.sh:

#!/bin/bash

export JAVA_OPTS="-Xms2048m -Xmx2048m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC"

./run.sh com.example.SecondApp -- "$@"
like image 118
tpunder Avatar answered Sep 28 '22 18:09

tpunder