Using Maven to push to Cloud Foundry with Java 8

September 29, 2014 Johannes Tuchsherer

featured-maven-CFMaven is still the tool of choice for many Java developers. Just take a look at a recent survey Java Tools and Technologies Landscape for 2014. The research states that 64% of the survey respondents use Maven, 16% use Ant, and 11% use Gradle. Whether you like it or not, you might have to work with Maven, and there is a vibrant and active community around Maven, dedicated to improving the support and tooling.

Recently, I learned that I can use the cloudfoundry-maven-plugin to easily push my Maven project to Cloud Foundry. Thanks to Scott Frederick, this little artifact of the Maven ecosystem is still alive and well maintained. There is a really good tutorial on how to use this plugin here. Generally, there is not much to add to the tutorial, but I found myself wishing for one thing while going through the instructions—an example app that I could use as a reference.

So, I decided to use my little Java toy app to show how to use the cloudfoundry-maven-plugin. I basically just followed the tutorial linked above. Please look at the pom.xml and the to see what I had to do to get the plugin working. I used Maven’s profile feature to easily switch between different CF environments. In my case, I used this to push either to a local bosh-lite install or Pivotal Web Services, but you can use the same mechanism to push to different spaces or orgs as well.

While adding the plugin and pushing my app to CF, I came across a couple of caveats:

  • By default the plugin doesn’t specify a buildpack, so the Cloud Foundry system buildpacks are used. If you are using a current version of Cloud Foundry (v183 as of 09/25/2014) and you are not using any custom buildpacks, you are using the Java buildpack version 2.4. This version does not support Java 8 by default. As a side note, version 2.5 changes this consideration, and it got released today. It is not yet promoted to be the system buildpack in cf-release, but you can track the progress in this PR against cf-release.

Since my little toy app uses Java 8, I had to use a different version of the Java buildpack. The easiest solution was to specify the buildpack URL in the configuration for the plugin. By doing so, it allowed me to use the master version of the Java buildpack which supports Java 8 by default.

  • After adding the simple plugin to my pom.xml like this:




I was hoping I could run a simple

$ mvn cf:help

to see the help text. Unfortunately, you have to specify your cf target, org, and space as a minimum to use this plugin. Also, the artifact has to be built and available in the target folder, otherwise you will get an error message. I filed a Github issue for this, and I am working on a PR to change the behavior so that you can run cf:help without this configuration.

Overall, using the cloudfoundry-maven-plugin was really easy and it made my development workflow much easier. Maven is still a very powerful tool. Its ecosystem remains vibrant and there is a lot of active development happening.

About the Author


Churn Prediction in Retail Finance and Asset Management (Part 1)
Churn Prediction in Retail Finance and Asset Management (Part 1)

Financial firms collect large volumes of data from all realms of our daily lives. These data assets are use...

An ‘Open’ Invitation to Oracle: Cloud Foundry Welcomes You
An ‘Open’ Invitation to Oracle: Cloud Foundry Welcomes You

As rumored early last week, today Oracle made news about its latest effort in the platform-as-a-service (Pa...

SpringOne 2021

Register Now