In order to use the Liberty Maven plug-in, it needs to be configured with Liberty profile installation information. The plug-in can be configured with an installation directory of a Liberty profile instance, a packaged server archive (.zip file with Liberty binaries), or with a packaged server that has been published as a Maven artifact.

Installing the Liberty runtime from the Liberty Repository

To install Liberty from the Liberty repository you will need the version number and the associated Liberty license code. The license code can be found in the relevant license file on the line starting with D/N::

Next, configure the Liberty Maven plug-in in the following way:


<plugin>
  <groupId>net.wasdev.wlp.maven.plugins</groupId>
  <artifactId>liberty-maven-plugin</artifactId>
  <configuration>
    <install>
      <licenseCode>license code</licenseCode>
      <version>version</version>
    </install>
    ...
  </configuration>
</plugin>

Installing the Liberty runtime from a custom location

To install Liberty from some other location, for example, from a web server within your organization, you will need to configure the plug-in with a Liberty license code and the location of the Liberty runtime archive to download and install.

To find the Liberty license code, run the following command on the Liberty runtime archive:

java -jar wlp*runtime.jar –viewLicenseInfo

Look for the line starting with D/N: in the output.

Next, configure the Liberty Maven plug-in in the following way:


<plugin>
  <groupId>net.wasdev.wlp.maven.plugins</groupId>
  <artifactId>liberty-maven-plugin</artifactId>
  <configuration>
    <install>
      <licenseCode>license code</licenseCode>
      <runtimeUrl>URL to Liberty runtime archive</runtimeUrl>
    </install>
    ...
  </configuration>
</plugin>

The Ferret sample application

The Ferret sample application is a simple web application that displays information about the HTTP requests, such as request parameters or HTTP headers sent. We extended the sample to use the Liberty Maven plug-in to download and install the Liberty runtime from the Liberty repository and to run the application.

Configuring the Liberty Maven plug-in

To set up the Liberty Maven plug-in for the Ferret sample we made the following changes:

  1. We created a server.xml configuration file for the application and placed it in the src/main/wlp directory. The server.xml enables the features required by the application and uses variables that can be used to pass environment-specific settings. Specifically, the server.xml uses the httpPort variable for specifying the port that the server listens to and the appLocation variable for specifying the location of the application to run.

    
    <server description="ferret server">
      <featureManager>
        <feature>jsp-2.2</feature>
        <feature>appSecurity-1.0</feature>
      </featureManager>
      <httpEndpoint id="defaultHttpEndpoint"
                    host="*"
                    httpPort="${httpPort}" >
        <tcpOptions soReuseAddr="true"/>  
      </httpEndpoint>
      <application name="ferret" context-root="/ferret"
                   location="${appLocation}" type="war" />
    </server>
    
       
  2. We updated the pom.xml file to define the Liberty Maven plug-in the pluginManagement section.

    
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>net.wasdev.wlp.maven.plugins</groupId>
          <artifactId>liberty-maven-plugin</artifactId>
          <version>1.1-SNAPSHOT</version>
        </plugin>
      </plugins>
    </pluginManagement>
    
       
  3. We added a pluginRepository entry to the pom.xml file. The repository contains the Liberty Maven plug-in.

    
    <pluginRepository>
      <id>sonatype-nexus-snapshots</id>
      <name>Sonatype Nexus Snapshots</name>
      <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </pluginRepository>
    
       
  4. We added a wlp Maven profile to the pom.xml file. The profile only activates if the IBM_LIBERTY_LICENSE environment property is set. This provides an option to build the sample without downloading and setting up the Liberty profile server first. In the wlp profile, the Liberty Maven plug-in is configured to create a new Liberty server with the server.xml configuration file from the src/main/wlp directory. The plug-in is also configured to pass two bootstrap properties: httpPort and appLocation. The httpPort property is set to port 9080. The appLocation property is set to the target directory that Maven creates for the built application. That way we do not have to copy any files to the server directory in order to run the application.

    
    <profile>
      <id>wlp</id>
      <activation>
        <property>
          <name>env.IBM_LIBERTY_LICENSE</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>net.wasdev.wlp.maven.plugins</groupId>
            <artifactId>liberty-maven-plugin</artifactId>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>create-server</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <install>
                <licenseCode>${env.IBM_LIBERTY_LICENSE}</licenseCode>
              </install>
              <configFile>src/main/wlp/server.xml</configFile>
              <bootstrapProperties>
                <httpPort>9080</httpPort>
                <appLocation>../../../../../${project.build.finalName}</appLocation>
              </bootstrapProperties>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    
    

Building and running the application

With the server.xml file created and the pom.xml file updated we can build the application and run it on Liberty profile:

  1. Set the IBM_LIBERTY_LICENSE environment variable with the correct license code to activate the wlp profile:

    $ export IBM_LIBERTY_LICENSE=license code
    
  2. Build the code as usual. With the IBM_LIBERTY_LICENSE environment variable set, the Liberty Maven plug-in will download and install the Liberty runtime and configure a server to run the application:

    $ mvn install
    
  3. Run the Liberty server with the application:

    $ mvn liberty:run-server
    

That’s it! Once the server is running, open http://localhost:9080/ferret in your web browser to see the application running.

Check out the Ferret sample repository on GitHub for the complete source code of this application. Also, see the Liberty Maven plug-in documentation for additional information about this feature. If you are using the Liberty Ant tasks, the wlp:install-liberty task provides equivalent functionality.

6 Comments on "Installing Liberty with the Liberty Maven plug-in"

  1. Are there any plans to release 1.1? We’re not keen to use snapshots in our CI.

  2. XavierVerges May 14, 2015

    This does not work for plugin version 1.0, only for 1.1-SNAPSHOT, right? I am getting `CWWKM2103E: No server assembly specified: specify either Maven coordinates in assemblyArtifact or a file in assemblyArchive` when running `mvn liberty:create-server` using plugin 1.0

  3. Hi,

    thanks for the great work!

    Ist this plugin a fork of the “official” liberty-maven-plugin? (groupId=com.ibm.websphere.wlp.maven.plugins).

    • We took the com.ibm.websphere.wlp.maven.plugins:liberty-maven-plugin and open-sourced it on GitHub. So, the net.wasdev.wlp.maven.plugin:liberty-maven-plugin is now the official Maven plugin for Liberty. The com.ibm.websphere.wlp.maven.plugins:liberty-maven-plugin is still available but it’s not being updated anymore. All the updates & enhancements are done in the open-sourced version.

Join The Discussion

Your email address will not be published. Required fields are marked *