I'm newbie both Payara and Heroku. Though I tried to play with these for preparing my presentation in Japanese GlassFish User Group event.
glassfish.doorkeeper.jp
About one month ago, I participated Japanese Salesforce event. It was called "Salesforce Summer".eventjp.salesforce.com
At the event, I saw Heroku demonstration. This is the reason why I started to use Heroku.After the event, I checked Heroku site and found good Java tutorial. In the tutorial, the sample Java web application used Spark.
I thought that ... if I use Payara Micro, is it possible to deploy Java EE application to Heroku ?
Finally, it could. Here is procedures.
Getting Started with Java on Heroku
Firstly, I started "Getting Started with Java on Heroku". The tutorial is very polite, so it's easy to do.
- Installing Toolbelt (for Windows on my environment)
- heroku login
After that, I cloned "java-getting-started" from github.
git clone https://github.com/heroku/java-getting-started.git
And changed directory.
cd java-getting-started
Next
heroku create
git push heroku master
heroku ps:scale web=1
heroku open
Finally I confirmed the deployed page.
These procedures are same as the tutorial.
PayaraMicro on Heroku
I used the same project, it means I used "java-getting-started" project cloned from GitHub.
It's kind of cheat I think. Normally, it had better create as new project.
Firstly, I changed pom.xml.
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>payara-micro</artifactId>
<version>4.1.153</version>
<type>jar</type>
</dependency>
Also, I edited the code like this.
import fish.payara.micro.BootstrapException;
import fish.payara.micro.PayaraMicro;
public class Main {
public static void main(String[] args) throws BootstrapException {
PayaraMicro.getInstance()
.setHttpPort(Integer.parseInt(System.getenv("PORT")))
.addDeployment("DeployTarget.war")
.bootStrap();
}
}
It's very important to call "setHttpPort(Integer.parseInt(System.getenv("PORT")))", because the port of HTTP on Heroku is binded random.
If that helps, I used NetBeans IDE.
After changing code, I copied from WAR file which is target of deploy to this project.
The War was created by Java EE 7, but I used only JSF and CDI.
Finally, I committed the code and "git push heroku master". Everything was done.
Here is my deployed Java EE app with PayaraMicro on Heroku :)
Enjoy!