Back in May, we announced the 172 release of Payara Server and mentioned a preview of our Maven plugin for Payara Micro, available on GitHub. Since then, we have released the plugin to Maven Central so, to illustrate it's use, I'll be revisiting my earlier blog on another feature of Payara Micro 172 - the ability to use Payara Micro as a JMS consumer.
I'll gradually modify the example from that blog post to make full use of the plugin. Full reference documentation for the plugin is available in ourdocumentation GitBook.
Bundle the ActiveMQ RAR into an Uber JAR
The first improvement we can make is to use the
payara-micro:bundlegoal to create an Uber JAR containing the ActiveMQ resource adapter. This will let us specify the Maven GAV coordinates of the ActiveMQ RAR so we don't have to bother downloading the artefact ourselves.
I've separated out the configuration properties I've set above.
This property is simply the version of Payara Micro we want to target for this application. We need at least 172 for the JCA support for ActiveMQ.
This property allows you to add a list of
<artifactItem>, which are just Maven GAV coordinates of applications to be deployed on the Payara Micro instance.
2. Deploy the built JMS11NotificationConsumer app
Our next step is to deploy the JMS11NotificationConsumer app using the
Here, I have made a couple of additions to my plugin configuration. I have added the
start goal, and some configuration options for that goal:
The default behaviour is not to use the bundled Uber JAR. Setting this property to true means that Maven will attempt to start the Uber JAR, rather than look for a path to an executable specified with
This property allows you to declare all the same command line options as are available when launching a Payara Micro instance from the terminal. Each
<option>must be specified as its own key/value pair.
Do be aware that the
<value> property must always have a value. For example, the
--autobindhttp property can be enabled on the command line without having to specify "true". This is not the case here; we must add the value for the option.
Why didn't we just add another artifact to the
<deployArtifacts>list of the
<deployArtifacts>list would have allowed us to bundle both the RAR and our application at once in an Uber JAR; meaning that everything is packaged in a single unit. The problem is that our JMS11NotificationConsumer application depends on the ActiveMQ RAR, so the RAR must be deployed first. When we package everything into the Uber JAR, we lose any concept of deployment order, so the application might try to deploy before the ActiveMQ RAR and fail when the Payara Micro instance is started.
This method does actually have some benefits when using a Docker container. Keeping a skinny WAR or JAR containing business logic separate means that there can be a significant benefit from Docker's layering system. The ActiveMQ RAR version will change far less frequently than our app and is where the majority of the disk space is taken up. Since Docker only builds the layers which change, this is likely to mean rebuilding (and pushing to a registry!) a few KB rather than a few MB.
Why didn't we use the
<deployWar>property of the
The reason we didn't use this is for the simple fact that we are creating an EJB JAR, not a WAR file, so this property would not have deployed our app. If the resulting artifact was a WAR, then this property would have worked with our configuration.
3. Refactor the application to avoid using a post-deploy command file
We could have simply reused the existing post-deploy.asadmin file from the previous blog and supplied that with another
<option> but, since that configuration can be done via annotations, it means we can include that configuration in the app and avoid having to maintain multiple files.
Here, I have added the
@ConnectionFactoryDefinition and created the notifierQueue with an
@AdministeredObjectDefinition annotation. The values of these properties are the same as I used in my previous blog.
4. Start Payara Server with the JMS notifier enabled
Finally, we need to start Payara Server with the healthcheck service pushing data through it the JMS notifier. This is covered in steps 5-7 in my previous blog but, to summarise, the asadmin commands to run against Payara Server are as follows:
We should now see the same results as we saw before but, now we have set up our Payara Micro environment with the plugin configuration, we have less work to do each time we want to see a change.
We can simply run the goals
mvn clean install payara-micro:bundle payara-micro:start and that should be enough!
There are lots of other features in the plugin which aren't covered in this blog post - a complete reference is available in our documentation. The biggest advantage to using this plugin is in creating an Uber JAR. Previously, users needed to use the Maven Exec plugin to call the
--outputUberJar option on a previously downloaded Payara Micro JAR. This meant that Payara Micro would need to start to create the Uber JAR, and then start again when actually running the created Uber JAR. Now, the bundle goal takes care of that, and Payara Micro does not need to start, meaning a big chunk of build time is eliminated.
There are lots of different ways you may choose to use this plugin and many ways to achieve the same goal, so there's sure to be something to fit your workflow!