There are 2 basic ways of running a Payara Micro service on Heroku:
I prefer to deploy applications as .War files rather than Fat Jars, so in this example, I'll show how to create a Heroku application and deploy a Payara Micro service to it.
To enable a Payara Micro application for running on Heroku, there are two simple steps we have to make. The first is to simply bundle the Payara Micro distribution file within the Maven project. (You could create a standalone app and completely use Maven, but I think this is a simpler solution). Download Payara Micro and place it in the
\lib folder of the Maven project.
|___.gitignore |___lib | |___payara-micro-184.108.40.206.jar |___pom.xml |___Procfile |___src | |___main | | |___java
The reason for deploying Payara Micro is simply that we need this to launch any service .War files. Remember, we could use a Fat Jar, if that's your preference.
Secondly, we need to create a file telling Heroku how to run the service that we are to deploy. This file,
Procfile needs to be created at the root of the Maven project structure as shown above. The contents of this file tell Heroku how to start Payara Micro and deploy the application:
web: java -jar lib/payara-micro-220.127.116.11.jar --deploy target/PayaraHeroku.war --port $PORT
There are a few things to say about the Procfile. You can see that this defines a web application that is invoked by
java -jar lib/payara-micro-18.104.22.168.jar. There are then a couple of Payara Micro command line options.
--deploy tells Payara Micro to deploy the result of the Maven build (
target/PayaraHeroku.war in this example).
--port $PORT tells Payara Micro to listen on the correct port that Heroku is using
So that's it, there are only 2 small changes needed to a Payara Micro service to enable it to run on Heroku. We need to add the Payara Micro runtime and create a Procfile.
Once you've created a Payara Micro application, it needs to be deployed on Heroku. Deploying a Heroku application is documented in depth on the Heroku Dev Centre. You'll find everything you need to know about deploying Java applications there, so I'll only go over this briefly.
The basic steps are to:
git add ... && git commit ...
git push heroku master
heroku ps:scale web=1
Once the git repository is pushed to Heroku, Heroku will work out that this is a Java application and will start the Maven build. This will create the artefact in the
target directory on Heroku which is referenced by the Procfile. Once the build is complete, Heroku will start the Payara Micro service using the options defined within the Procfile.
And that's it! As you can see, there's very little you need to do to be able to get your Payara Micro services running on Heroku.
At Develop In Java, we've been a part of the Java community for over 10 years. If there's anything you'd like us to cover, just ask !