Joyful Open Liberty Developer Experience with Liberty Maven Plugin

Last Updated:  December 9, 2019 | Published: November 30, 2019

Short feedback cycles during development are essential for your productivity. If you practice TDD you'll agree on this even more. In the past, I've used several IDE plugins to achieve this for developing Jakarta EE applications. All worked but it wasn't joyful. Adam Bien's Watch and Deploy was a light at the end of the tunnel for a simple & generic solution. Recently I stumbled over the Liberty Maven Plugin from the Open Liberty team. This is really a gamechanger for great development experience for Liberty profile servers.

TL;DR: You'll achieve the following with this Maven plugin:

  • Hot-reloading of code/configuration/dependency changes
  • TDD joy for developing Jakarta EE and MicroProfile applications
  • Easily debug your deployed application
  • Start your Open Liberty server without manual effort

Integrate the Liberty Maven Plugin to your project

Integrating this Open Liberty Maven plugin to an existing project, is as simple, like the following:

Open Liberty server configuration

By default, the plugin makes use of your configuration within src/main/liberty. To now configure the server, we can place our server.xml within src/main/liberty/config:

If you, later on, start the Open Liberty server, you'll find this file within target/liberty/wlp/usr/servers/defaultServer. To provide further resources e.g. a JDBC driver like in the example above, just place them next inside the same directory like your server.xml. You can also create new folder structures to separate the files from each other.

Similar to this, you can configure server parameters like environment, JVM or Liberty specific variables with this plugin. Since plugin version 3.1, you can achieve this within the properties section of your pom.xml:

The liberty.env can be then used for example by MicroProfile Config. The liberty.var variables are available within your server.xml for further configuration like it did with the name of the H2 database.

Find a list of all possible server configurations here.

Open Liberty in development mode = joy

Now comes the joyful part…

With this plugin you can launch the Open Liberty server on your machine in development mode:

mvn liberty:dev

If you execute this for the first time, the plugin will download the openliberty-kernel and all the required features you need. These files are stored within your local Maven repository folder (usually ~/.m2/repository) and can be therefore used for multiple projects.

Once all artifacts are downloaded, your Open Liberty server starts in development mode. If you now change the source code of your application, the plugin compiles and deploys your changes to the running server in a matter of seconds.

This is not limited to changes to your code. You can also add new dependencies to your Maven project or adjust your server configuration. Even if you add new features to your server.xml, they will be installed automatically.

Furthermore, you can run your (unit & integration) tests on-demand with hitting enter. In addition to this,  if you start the development mode with -DhotTests, your tests are executed on each change:

mvn liberty:dev -DhotTests

This is a gamechanger for the TDD (Test Driven Development) experience with Open Liberty.

Once Open Liberty is running in this development mode, you can also debug your application. The default port is 7777 and you can easily attach your IDE to the running JVM and debug your application.

To exit the development mode, either enter q in your terminal and hit enter or exit with CTRL+C.

Other Maven plugin goals

Besides this development mode, you can also start and stop your Open Liberty server with this project. The Maven goals for this are mvn liberty:start and mvn liberty:stop. The server content is located at target/liberty. There is no need to manually download Open Liberty anymore, as this plugin will do this.

If you want to start Open Liberty in the foreground, replace the start goal with run.

There are more useful goals for this Maven plugins to explore e.g dump, debug, create. The full list of goals is available on GitHub.

Summary of the Open Liberty Maven Plugin

With this Maven plugin, your Jakarta EE or MicroProfile development experience will takeoff. Given this plugin, there is no need to download the latest server anymore. The conventions for the server configuration makes it also more convenient to use compared to achieving the same with Docker.  This plugin will definitely be part of all my further Open Liberty projects and I can't imagine developing applications without it anymore.

For a hands-on example, I've recorded a YouTube video:

Clone the example application for this review from GitHub or quickly add the plugin to your own project to see how joyful it makes developing with Open Liberty. There is also a recording available at the Open Liberty blog.

If you are looking for a solution to achieve hot reloading for other application servers, have a look at Adam Bien's WAD.

Have fun using the Open Liberty Maven Plugin,

Phil

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Sign up for Our Mailing List And Get

the Testing Java Applications ($9) Cheat Sheet for Free

Testing Java Applications Cheat Sheet Cover
>