The Payara Micro 173 release had a few changes which will make the lives of Docker users easier. This blog will cover the changes which affect Payara Micro in Docker, demonstrating the following:
Using the new Payara Micro 5 Docker image, which provides Java EE 8 features.
Deploying applications without the targetted database being present.
Adding library JARs from the command line.
New Payara Server 5 Snapshot Docker images
We have recently begun publishing snapshot builds of Payara Server and Payara Micro 5, our next major version of Payara Server which provides updated APIs such as CDI 2.0. Along with the 173 release of Payara Server, we also began publishing 5-SNAPSHOT tags of our official Docker images which are built daily. These can be used as follows:
- docker run -it payara/micro:5-SNAPSHOT
- docker run -it payara/server-full:5-SNAPSHOT
Adding library JARs from the command line
Payara 5 snapshots also include the latest changes to Payara 173, which means that both the Payara Micro 5 and Payara Micro 173 images have the new
--addJars command option. This option can be used in multiple ways depending on the need. The following usages are supported:
- Adding a single JAR library
java -jar payara-micro.jar --addJars myLib.jar
- A directory of JAR libraries
java -jar payara-micro.jar --addJars myLibraryDirectory/
- Adding a colon-separated list of JARs and/or directories (similar to the Java classpath)
java -jar payara-micro.jar --addJars myLib.jar:myLibraryDirectory/:myOtherLib.jar
--addJarsin combination with
--outputUberJARwill package all libraries into the JAR so that the long command does not need to be specified each time.
java -jar payara-micro.jar --addJars myLib.jar --ouputuberjar payara-micro-with-libs.jar
Deploying applications without checking the database
With Payara 173, applications can now be deployed regardless of whether the target database is available. This is extremely useful to users of container-based services since there is no need to start a database inside the container for the application to deploy during the build cycle of the image. This means that the application will be successfully deployed more quickly, more reliably, and the container can start with everything already deployed and configured. Previously, the application may be left undeployed but the container would keep the server running and deem it to be healthy.
To demonstrate these features, I have created a test project. The application creates a connection to a database on the server "database" every time
/ping is visited, and returns the validity of the connection. The application contains two short classes and a
glassfish-resources.xml. The full source code for this example is available in our Payara Examples repository, Payara-Examples/Payara-Micro/database-ping.
The Dockerfile to use this application with Payara Micro is shown below:
Since the application will be deployed regardless of whether the database is available or not, the images can be started in any order (as long as the Payara Micro image has a link to the database server). This means that these images would work together in a Docker Swarm environment. But just for ease, we can just run the following commands:
After this you can then go to
http://localhost:8080/myapplication/ping, where you should get the following response:
Before 173, you might have gotten the following error (as well as an "
--addJars is not a valid command line argument" error!) in the Payara logs:
This is because Payara Server would detect that the required database wasn’t running, and would be unable to create the resource for it. This isn’t the case anymore however.