Maven is arguably the most popular build and test tool for Java projects. The new WebSphere Application Server Liberty Profile provides a set of plugins that enable control of the server to start, stop and deploy applications from within a maven build.

by Dan Lu

What is the WebSphere Application Server V8.5 Liberty Profile maven plugin?

All maven work is done by plugin. Maven itself provides a list of general plugin for end-user usage, such as compile, deploy. But its plugin framework also makes any project implement its own plugin to operate its own product such as tomcat, jetty maven plugin. WAS 8.5 maven plugin targets for this also: operate WAS 8.5 server.

Configuring maven to use the plugins

The maven plugin is configured into your build as a pluginRepository as shown in Listing 1.

Listing 1. Plugin repository for using Liberty profile maven integration

<pluginRepository>
    <id>Liberty</id>
    <name>Liberty Repository</name>
    <url>http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/</url>
    <layout>default</layout>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <releases>
        <enabled>true</enabled>
    </releases>
</pluginRepository>

How to use

As we know, maven defines a goal to implement a task. WAS 8.5 maven plugin provides multiple goals to operate server.

Install, Start, Stop, Package , Create server

You can install, start, stop, package and create server via goals:

 

  • liberty:install-server
  • liberty:start-server
  • liberty:stop-server
  • liberty:package-server
  • liberty:create-server

Install server

Install server from a local zip or an pre-installing directory, the most import maven feature, you can install a server from a maven artifact if the server exists as artifact in local or remote maven repository.

Goal Usage:

mvn liberty:install-server -DserverHome=/path/to/server_home -DserverName=[server_instance_name]

For example:

Listing 1. This sample shows install a server from a pre-existing directory

<plugin>
    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId> 
    <configuration>
        <serverHome>${project.build.directory}/wlp</serverHome>   
        <background>true</background>
        <serverName>test</serverName> 
    </configuration>
</plugin> 

 

Goal Usage:

mvn liberty:install-server -DassemblyArtifact=[maven_artifact] -DserverName=[server_name]

For example:

 

Listing 2. This sample shows install a server as maven artifact

<plugin>
<!-- install the liberty server zip into the local maven repo -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <id>install-liberty-to-repo</id>
            <phase>process-resources</phase>
            <goals>
                <goal>install-file</goal>
            </goals>
            <configuration>
                <file>wlp***.zip</file>
                <groupId>com.ibm.ws.liberty.test</groupId>
                <artifactId>liberty-test-server</artifactId>
                <version>1.0</version>
                <packaging>zip</packaging>
            </configuration>
         </execution>
<!—install the liberty server as maven artifact<plugin>
    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>install-liberty-server</id>
            <phase>compile</phase>
            <goals>
                <goal>install-server</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <assemblyArtifact>
            <groupId>com.ibm.ws.liberty.test</groupId>
            <artifactId>liberty-test-server</artifactId>
            <version>1.0</version>
            <type>zip</type>
        </assemblyArtifact>
    <serverName>test</serverName>
    </configuration>
</plugin>

 

Goal Usage:

mvn liberty:install-server -DassemblyArchive=/path/to/assembly.zip

For example:

 

Listing 3. This sample shows install a server archive

<!—install the liberty server as maven artifact
<plugin>
    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <configuration>
        <assemblyArchive>/path/to/server archive</assemblyArchive>
    </configuration>
</plugin>

Start server

Start a server from a pre-install directory. If the server instance doesn’t exist, it will automatically create one for you. You don’t have to define a create goal.

Goal Usage:

mvn liberty:start-server -DserverHome=/path/to/server_home -DserverName=[server_name]

For example:

Listing 1. This sample shows start a server

<plugin>
    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId> 
    <executions>
        <execution>
            <id>start-server</id>
            <phase>pre-integration-test</phase>
             <goals>
                <goal>start-server</goal>
            </goals>
            <configuration>
                <serverHome>${project.build.directory}/wlp</serverHome>
                <serverName>test</serverName>
            </configuration>
        </execution>
    <executions>
</plugin>

Package server

Package a server.

Goal Usage:

mvn liberty:package-server -DserverHome=/path/to/server_home -DserverName=[server_name] -DpackageFile=/path/to/packaged server file location

For example:

Listing 1. This sample shows package a server

 <plugin>
    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>package-server</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>package-server</goal>
            </goals>
            <configuration>
                <serverHome>${project.build.directory}/was4d</serverHome>
                <serverName>test</serverName>
                <packageFile>/path/to/packaged server file location</packageFile>
            </configuration>
        </execution>
    </executions>
</plugin>

Stop server

Install server from a local zip or an pre-installing directory, the most import maven feature, you can install a server from a maven artifact if the server exists as artifact in local or remote maven repository.

Goal Usage:

mvn liberty:stop-server -DserverHome=/path/to/server_home -DserverName=[server_name]

For example:

Listing 1. This sample shows stop a server

<plugin>
    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>stop-server</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop-server</goal>
            </goals>
            <configuration>
                <serverHome>${project.build.directory}/wlp</serverHome>
                <serverName>test</serverName>
            </configuration>
        </execution>
    </executions>
</plugin>

Create a server

Create a server.

Goal Usage:

mvn liberty:create-server -DserverHome=/path/to/server_home -DserverName=[server_name]

For example:

Listing 1. This sample shows create a server

<plugin>
    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <executions>
            <execution>
                <id>create-liberty-server</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>create-server</goal>
                </goals>
                <configuration>
                    <serverHome>${project.build.directory}/wlp</serverHome>
                    <serverName>testcreate</serverName>
                </configuration>
        </execution>
    </executions>
</plugin>

Deploy and undeploy applications

EAR, WAR, EBA modules can be deployed into a running liberty server using the goal. Multiple modules can be specified as maven artifacts in which case they will be retrieved from the local maven repository or a single module can be specified by it’s absolute file location

Goals:

 

  • liberty:deploy
  • liberty:undeploy

Deploy applications

You can deploy applications to server one by one.

Goal Usage:

mvn liberty:deploy -DserverHome=/path/to/server_home -DserverName=[server_name] -DappArchive=/path/to/apps to be deployed

For example:

Listing 1. This sample shows deploy an application

 <plugin>
    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>deployapp</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>deploy</goal>
            </goals>
            <configuration>
                <appArchive>${project.build.testOutputDirectory}/SimpleOSGiApp.eba</appArchive>
            </configuration>
        </execution>
    </executions>
</plugin> 

Undeploy applications

You can undeploy applications from server.

Goal Usage:

mvn liberty:undeploy -DserverHome=/path/to/server_home -DserverName=[server_name] -DappArchive=/apps' name to be undeployed

For example:

Listing 1. This sample shows undeploy an application

<plugin>
    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>undeploy</id>
            <goals>
                <goal>undeploy</goal>
            </goals>
            <configuration>
                <appArchive>foo.ear</appArchive>
            </configuration>
        </execution>
    </executions>
</plugin>

2 comments on"Play with WebSphere Application Server V8.5 Liberty Profile in maven world"

  1. I need following clarifications.
    1. I have app with ejb 1 deployed to was server. Can i use maven liberty plugin to build this app instead of RAD.
    2. I have 3 modules in same ear having circular dependeny. Will maven plugin resolves circular dependency while build.
    3. Can i do ejbdeploy with liberty plugin after build project

    • 1. Yes, you can use this plugin to deploy applications to WebSphere Liberty app server.
      2. In general, you cannot have circular dependencies between Maven projects. One way to avoid dealing with circular dependencies is to create one Maven project for all your modules.
      3. No. ejbdeploy is a traditional WebSphere tool and Liberty Maven plugin has no support for it.

Join The Discussion

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