Run web application with Liberty Maven plugin

Open Liberty is also a Java Server runtime that helps us run Java web applications. Using the Liberty Maven plugin will help us quickly deploy the application to Open Liberty easily during development. In this tutorial, I will show you how to use this Liberty Maven plugin!

First, I will create a new Jakarta EE Maven project as an example:

I will not use the Maven Jetty plugin to run this project but will use the Liberty Maven plugin.

You can declare the Liberty Maven plugin as follows:

with:

For this plugin to work, we need to define information about the Open Liberty server in a file named server.xml located in the /src/main/liberty/config directory:

The contents of this server.xml file are as follows:

with 2 properties “default.http.port” and “default.https.port” defined in pom.xml file as follows:

Liberty Maven plugin will automatically replace the value of properties with the key starting with liberty.var, declared in the pom.xml file with the properties declared in the server.xml file.

With the Liberty Maven plugin, we need to define the feature we want to run in this server.xml file. As you can see, here I am running Jakarta EE 9.1, so I have declared this feature in the <featureManager> tag. You can see the full features of Open Liberty here.

Now, if you run the application in Maven with “mvn clean liberty:run” and go to the address http://localhost:9080/, you will see the following output:

With the declaration in the file server.xml, our application will run at the address http://localhost:9080/jakartaee-liberty/!

The following results:

Liberty Maven plugin supports us live coding, which means Open Liberty will automatically load our changes in the code during development. You can run the Maven command “mvn clean liberty:dev” to do this, making our development process faster, very convenient!

Add Comment