This article describes deploying Maven-based applications directly from source to IBM Cloud using the Heroku buildpack for Java applications and the Liberty Maven plug-in.

The IBM WebSphere Application Server Liberty Buildpack is used to deploy Liberty applications to IBM Cloud and other Cloud Foundry-based platforms. The Liberty buildpack deploys compiled artifacts such as .war or .ear files, server packages (.zip files), or server directories.

However, it is also a common scenario to deploy the application source code instead of the compiled artifacts. Specifically, where the compilation of the source happens on the cloud during application staging. With this approach, the application is built on the same platform and the same environment as it will be running on. Also, as the source code is usually managed by a version control system, this approach makes it easier to track the actual source code changes associated with a particular deployment of the application.

The Heroku buildpack for Java applications is a buildpack that downloads and installs a JDK and Apache Maven. It then executes the Maven build command to build the application source. On IBM Cloud, the Heroku buildpack can be used to deploy Maven applications from source.

Once the application is built using the buildpack, a runtime is needed to run the application. In a previous article, Installing Liberty with the Liberty Maven plug-in, we described how the plug-in can be configured to download and install Liberty from the Liberty repository. We will use that method to install the runtime when deploying to IBM Cloud. We will also extend the Ferret sample described in that article to configure it for deployment to IBM Cloud.

Deploying the Ferret sample application to IBM Cloud

The Ferret sample application is a simple web application that displays information about HTTP requests. In the pom.xml file, the sample has the wlp Maven profile which activates the Liberty Maven plug-in. When activated, the plug-in will download and install the Liberty runtime and configure a Liberty server to run the application.

In the wlp profile, the server is also configured with two bootstrap properties: httpPort and appLocation. The httpPort property is used for specifying the port that the server listens to and the appLocation property is used for specifying the location of the application to run.

Adding the bluemix profile

For IBM Cloud (formerly known as IBM Bluemix), we just need to override the httpPort property to pass the port that IBM Cloud assigns to the application. That is best done in a separate bluemix profile which we added to the pom.xml file:


The bluemix profile will be activated when the VCAP_APPLICATION environment variable is set. Since that environment variable is always set on IBM Cloud, the profile will be automatically activated during staging.

Once the application is successfully staged, IBM Cloud also sets the $PORT environment variable. It indicates the port number the application server should listen to for HTTP traffic.

Since the $PORT environment variable is only set after staging, we must ensure that this variable is resolved right when the Liberty server is started. That is why the httpPort property is set to $${env.PORT} value. Without the extra $ in front of ${env.PORT}, Maven would attempt to resolve the variable at the build time during staging. That would cause the file to be updated with an incorrect httpPort value.

With the bluemix profile added to the pom.xml file we are almost ready to deploy the application. We created a manifest.yml file with contents below that makes it easy to deploy the application to IBM Cloud:

   path: .
   command: $HOME/target/liberty/wlp/bin/server run
     IBM_LIBERTY_LICENSE: <license code>

The manifest file specifies the URL for the Heroku buildpack and the command that IBM Cloud will use to launch the Liberty server. It also specifies the IBM_LIBERTY_LICENSE environment property that will activate the wlp profile and cause the Liberty Maven Plug-in to download and install Liberty runtime during the build.

The IBM_LIBERTY_LICENSE property in the manifest.yml file needs to be set to the Liberty license code. The license code can be obtained by reading the current Liberty license and looking for the line that starts with D/N: text.

Once the environment property is properly set we are ready to push the application to IBM Cloud:

$ cd sample.ferret
$ cf push app_name

Once the application is successfully deployed, open in your web browser to see the application running.

For the complete source code for this application, check out the cloud branch in the Ferret sample GitHub repository.

1 comment on"Deploying to IBM Cloud with Liberty Maven Plug-in"

  1. Hi Jarek,

    the buildpack currently doesn’t work on Bluemix. I’m getting an error during the maven build:

    /tmp/staged/app/.jdk//bin/java: /lib/ version `GLIBC_2.14′ not found (required by /tmp/staged/app/.jdk/bin/../lib/amd64/jli/

    Any ideas on that? For me the only option seems to be to go back to the Liberty buildpack…

Join The Discussion

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