Running 2nd non-web java app process in Heroku

434 views Asked by At

I was wondering if it's possible to run a non-web java app in Heroku from within a web java app? Basically I want to execute a command to run the non-web app jar:

Calling something like this in Heroku for one off process:

Process proc = Runtime.getRuntime().exec("java -jar A.jar");
1

There are 1 answers

2
codefinger On BEST ANSWER

You probably don't want to execute the new process from the existing Java process. Instead, you should create a new process type in your app's Procfile, like this:

web: java -jar webapp-runner.jar yourapp.war
worker: java -jar A.jar

Then you can run the worker process from the CLI heroku run worker, or you can make an HTTP call to the Heroku API.

I assume you are using heroku war:deploy, which means you probably don't have a Procfile at this time. You may need to switch to heroku jar:deploy and include webapp-runner in your app manually.