There are many different frameworks that allow you to develop and deploy microservices. Payara, the team behind the Payara Server have a couple of options for deploying microservices - PayaraMicro and Payara MicroProfile. So, what exactly are PayaraMicro and Payara MicroProfile?
What is Payara Micro?
Both PayaraMicro and Payara Microprofile are small .jar files that allow you to deploy .war files from the command line allowing Java EE applications to be easily executed.
PayaraMicro is described as:
small, <70 MB in size and incredibly simple to use. With its automatic and elastic clustering, Payara Micro is designed for running Java EE applications in a modern containerized/ virtualized infrastructure, using automated provisioning tools like Chef, Ansible or Puppet.
and supports the following Java EE APIs.
- Servlets, JSTL, EL and JSPs
- EJB lite
- Bean Validation
Payara MicroProfile follows the MicroProfile initiative led by IBM, the London Java Community, RedHat, TomiTribe, Payara and SOUJava and provides support for the following APIs.
Essentially, Payara MicroProfile is a cut down version of Payara Micro.
OK, so we’ve got a pretty good understanding of what Payara Micro / MicroProfile are, but how can they be used to deploy Java EE applications?
Downloading Payara Micro
Both installations can be downloaded as a .jar file from Payara’s web site. The downloades are based on the full version of Payara Server, which is in turn based on the latest version of GlassFish 4.
Deploying onto Payara Micro
To deploy and run an application using Payara Micro (from hereon, when I refer to Payara Micro, I mean Payara Micro or Payara MicroProfile), we execute Payara Micro and tell it to deploy the application. This is different from technologies such as WildFly Swarm, which requires application specific APIs to develop and deploy the application.
For example, to deploy a JAX-RS application in WildFly Swarm, we need to build and deploy with the appropriate Swarm artifacts:
With Payara Micro, this is not necessary - the only dependency we have is Java EE itself.
Starting up Payara Micro and deploying an application is a case of executing the following command:
java -jar payara-micro-126.96.36.199.jar --deploy <app.war>
<app.war> is the path to the .war file to deploy.
[2016-12-29T21:41:37.471+0000] [Payara Micro 4.1] [INFO]  [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1483090897471] [levelValue: 800] Deployed 1 archives
[2016-12-29T21:41:37.472+0000] [Payara Micro 4.1] [INFO]  [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1483090897472] [levelValue: 800] Payara Micro 188.8.131.52 #badassmicrofish (build 28) ready in 17990 (ms)
That’s all there is to it. We can easily start Payara Micro and deploy a .war file to it without having to add any specific MicroProfile content into the codebase.
As a word of caution, it’s worth noting the APIs that Payara Micro supports however. For example, if you try to use JAX-WS, the chances are your application won’t deploy and won’t work! Stick to the supported API’s and you should be ok.
Creating an UberJar Distribution
We’ve just seen how to start and deploy an application using Payara Micro. We can also use Payara Micro to create an UberJar if we wish to distribute applications as a single .jar
Creating the UberJar is simply a matter of appending the relevant command line parameters onto Payara Micro.
$ java -jar payara-micro-184.108.40.206.jar --deploy <app.war> --outputUberJar MyApp.jar
Dec 29, 2016 22:12:58 AM fish.payara.micro.PayaraMicro packageUberJar
INFO: Building Uber Jar... MyApp.jar
Dec 29, 2016 22:13:14 AM fish.payara.micro.PayaraMicro packageUberJar
INFO: Built Uber Jar MyApp.jar in 15439 (ms)
Command Line Options
In this post, we’ve just looked at a couple of the command line parameters to Payara Micro (
--outputUberJar). There are many more parameters that can be used for example, setting the HTTP port or maximum number of HTTP threads. Details of these options are provided on the Payara Micro wiki
Payara Micro is a lightweight way of executing Java EE applications supporting the relevant APIs. Its easy to use, but provides flexibility and many of the features of it’s big brother - Payara Serve