Getting Started with Eclipse MicroProfile, Part 2: Payara Micro
Payara Micro is a MicroProfile implementation from the good folks at Payara, based on Payara Server, which is itself
based on GlassFish. Whew! If you’re familiar with either GlassFish or Payara, you should feel right at home with Payara
To start, we need to understand how Payara Micro deploys the application. Payara Micro spins up an instance, albeit a
somewhat stripped down version, of Payara Server. Once the server instance has started, Payara Micro deploys your MP application
as a web application. In your build file (and we’ll be using Maven), you must declare that you are building a war file:
Next, we need to declare the dependencies for Payara Micro, but we also need to declare a dependency on our common
module, as that’s where the actual application lives. The Payara Micro module here has no real application data in. :)
Next, we can add the Payara Micro Maven Plugin to build, which will allow us to start and stop the server using Maven. We
will also add some configuration for the Maven Dependency Plugin to copy the Payara Micro jar to the build output directory
so that we can start and stop the server from the commandline:
That’s all there is to it. For using Payara Micro as an Arquillian container, there is no need, at least in the most basic
of usages, for arquillian.xml.
To run this test from IDEA, there seems to be a bit of extra work needed. It seems that Payara Micro depends on the
environment variable MICRO_JAR to tell the bootstrapping code where to find the JAR. It’s on the classpath, but that
doesn’t seem sufficient (I can, of course, be way off base — I’m not an expert on Payara Micro or Arquillian), so here
are the changes to my POM that I needed to make things work:
It also seemed that I needed to run the tests from the command-line first to make sure the JAR file was in place, as it
seems that IDEA does not run the usual Maven lifecycle prior to running the tests. Again, I’m no expert, so if someone
who is can clear up the confusion, I would greatly appreciate it.
Finally, one last test, which will exercise our REST endpoint end-to-end:
We tell JUnit to run the test with Arquillian, and that we want to run the tests on the client. Ordinarily, Arquillian
magically wraps up your tests, ships them to the server, and runs them there. For this test, we don’t want that, thus
@RunAsClient. Using the Apache HttpClient from HttpComponents, we make an "out of process" REST request to the endpoint
and verify the responses.
And there you have a very basic Payara Micro example, complete with working Arquillian tests. The thing to take away from
this is how simple it is to wrap your application in a Payara Micro runtime: the only additional work was configuring your
build to output the uberjar. That’s awesome, as that means there’s no real application glue required for the specific runtime
environment. We’ll see that this mostly holds true across the other MicroProfile, thus demonstrating the power of
standards and portability.