The OpenLiberty Maven plugin

With the OpenLiberty Maven plugin, it is possible to manage compilation, deployment, and packaging by executing Maven goals. Besides other service-level tasks, the following maven goals are considered to be the pillars of Microservice handling with OpenLiberty:

  • Generate a self-contained, executable archive with liberty:package-server.
  • Start a rightsized OpenLiberty.io for automatic fast redeployments with liberty:run-server.
  • Start or stop new OpenLiberty instance in a separate process with liberty:start-server.
  • Deploy/undeploy Microservice with liberty:deploy and liberty:undeploy.

In order for OpenLiberty.io to provide all the functionality, these three steps must be taken:

  1. Declare an OpenLiberty Maven parent.
  2. Declare and configure the OpenLiberty plugin.
  3. Create the OpenLiberty configuration.

All three steps are required. The first two steps are to be taken in Maven's pom.xml file. To fulfill the third step, creating a server.xml file with the OpenLiberty configuration is necessary. The OpenLiberty Maven parent is a convenient way to provide all the tooling required for the Maven plugin to work and not to force the developer to learn the internal mechanisms of OpenLiberty.

The code below shows a  <parent> XML tag:

    <parent>
<groupId>net.wasdev.wlp.maven.parent</groupId>
<artifactId>liberty-maven-app-parent</artifactId>
<version>2.0</version>,
</parent>

At the time this book was written, the latest version of liberty-maven-app-parent was 2.0. However, it is anticipated that there will be a significant number of improvements introduced in the future. Using the latest version may be an advantage as it will provide the latest code with bug fixes. 

As a second step, the OpenLiberty Maven plugin is declared and configured. In a typical Maven project, there is more than one plugin involved. In the following example, the OpenLiberty Maven plugin declaration is placed into the <plugin> XML tag, among other commonly used plugins, such as the compiler plugin or war-plugin:

<plugin>
<groupId>net.wasdev.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<assemblyArtifact>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-runtime</artifactId>
<version>${openliberty.runtime.version}</version>
<type>zip</type>
</assemblyArtifact>
<serverName>${project.artifactId}Server</serverName>
<stripVersion>true</stripVersion>
<configFile>src/main/liberty/config/server.xml</configFile>
<packageFile>${package.file}</packageFile>
<include>${packaging.type}</include>
<bootstrapProperties>
<default.http.port>${testServerHttpPort}</default.http.port>
<default.https.port>${testServerHttpsPort}</default.https.port>
<app.context.root>${project.artifactId}</app.context.root>
</bootstrapProperties>
</configuration>
<executions>
<execution>
<id>package-server</id>
<phase>package</phase>
<goals>
<goal>package-server</goal>
</goals>
<configuration>
<outputDirectory>target/wlp-package</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

The plugin introduces several configuration variables and behaviors. The behaviors are binded to various Maven goals. The preceding code provides a more advanced example of many useful configuration options OpenLiberty provides. There are reasonable defaults for most of the properties mentioned. The plugin declaration contains the following:

  • The plugin itself, including a group identifier, artifact identifier, and version
  • Binding of the package-server goal to the standard Maven package goal
  • The path to the server configuration file
  • Additional properties, including server name or startup port to bind to

Plugin declaration is a self-explaining step and easy for readers with previous knowledge of Maven. In the <execution> section, a Maven goal named liberty:package-server, introduced by the OpenLiberty Maven plugin is bound to the standard Maven's package goal. As the liberty:package-server goal produces a self-contained application with a rightsized OpenLiberty runtime inside, binding it to Maven's package goal ensures that an up-to-date version of such self-contained Microservices is produced every time a standard WAR is produced. This enables developers to automate the OpenLiberty solution creation.

If we remove this binding, a manual invocation of liberty:package-server is required to produce a self-contained, distributable application based on OpenLiberty. It is left to the user's discretion whether they want to go for automated or manual invocation of package-server.

Example command:

mvn liberty:package-server -DserverHome=/path/to/home -DserverName=somenamehere
                           -DpackageFile=/filename.zip
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.17.140