Petesta
Petesta

Reputation: 1775

Running multiple applications with sbt

I have my directory structure set up as such.

src/main/scala/main/Main.scala
src/main/scala/scripts/MainScript.scala

The script is a background job that will be running.

I've used sbt-assembly before to package up the main file into a jar to be deployed but I'm not sure how to create the two separate jars with sbt-assembly or sbt-native-packager. How would I go about doing that and what would be the best approach for this problem?

I would be looking to do something similar to this.

java -jar main.jar $PORT
java -jar scriptMain.jar

Upvotes: 4

Views: 915

Answers (1)

Muki
Muki

Reputation: 3641

One way to solve this only with native-packager would be the following.

  • Put all your main classes in src/main/scala
  • Define a mainClass in Compile := Some("foo.bar.Main") that should run as default
  • add additional scripts in src/universal/bin that you would like to provide. These scripts can call the main script generated by native-packager and set the -main parameter to the class you want to call.

Now you have an output package (e.g. a zip, rpm, deb) that has the following structure. Assuming your app is called myApp and you provided to other bin scripts called otherApp1 / otherApp2

lib/ (jars live here)
conf/ (configuration files here, if any)
bin/
  myApp
  otherApp1
  otherApp2

Unfortunately I have no example for the script (my bash-foo isn't good enough for instant magic on SO). In the end the scripts (otherApp1,otherApp2) should just pass the parameters they receive to the native-packager script (myApp).

There is an issue #633 that provides an automated way to generate scripts like this.

hope that helps, Muki

Upvotes: 1

Related Questions