Over a million developers have joined DZone.
Platinum Partner

Running Maven Applications on OpenShift PaaS

· Cloud Zone

The Cloud Zone is brought to you in partnership with Mendix.  Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.

As you know I'm in the middle of completely overhauling and open-sourcing my PhD thesis system (more here: Qualitas). I didn't work at Gdańsk University of Technology any more and I had to find some kind of a server where I could setup a live demo of the system.

Two weeks ago I stumbled upon OpenShift. It's a division of Red Hat which offers you free cloud PaaS services for your applications. By default OpenShift comes with pre-defined platforms for Java EE, PHP, Python, Perl, Node.js, Ruby, and Do-It-Yourself (DIY) applications. DIY applications turned out to be extremely powerful. As a proof of concept I decided to deploy my Apache Camel route (with Apache CXF endpoint as a front-end).

There was one trick to make it all work, but thanks to the OpenShift community I got it working like a charm. See how I did it.

Running DIY applications on OpenShift

Using OpenShift is pretty straight forward. You create an account, then you create an application. Next you get OpenShift Git address where you upload your code. OpenShift automatically exposes all applications (even old school C) which listen on 8080 port. DIY application comes with a few action hooks. They all are stored in a hidden directory .openshift/action_hooks. The most important hooks are:
Names speak for themselves. And in case you haven't figure it out yet, OpenShift, as a Red Hat division, uses Linux machines  :)

Running Maven 

OK, so I started from writing simple start and stop action hooks respectively:
nohup mvn -f qualitas-internal-monitor-camel/pom.xml camel:run &
kill `ps aux | grep camel:run | awk '{print $2}'`
When I pushed my application, I saw Maven message complaining about not being able to create .m2/repository directory. Now, to cut long story short Maven installed on your platform doesn't have write permissions to your home directory. Setting M2_REPO to a writable directory $OPENSHIF_DATA_DIR did not help either because Maven installed on your platform ignores it. The trick (thanks Ram!) was to create settings file and pass it to Maven. The final start action hook looked like this:
mkdir -p $OPENSHIFT_DATA_DIR/m2/repository
echo -e "<settings><localrepository>$OPENSHIFT_DATA_DIR/m2/repository</localrepository>\n</settings>\n" > $OPENSHIFT_DATA_DIR/settings.xml
nohup mvn -s $OPENSHIFT_DATA_DIR/settings.xml -f qualitas-internal-monitor-camel/pom.xml camel:run &

Points to note

  • $OPENSHIFT_DATA_DIR - is persisted between deployments and is a perfect place for Maven repository :)
  • Check the directory you're in. After I fixed repository stuff, Maven couldn't find my pom.xml file. That is why in the above start hook I change directory to $OPENSHIFT_REPO_DIR.
  • First my CXF endpoint was listening on localhost:8080, this endpoint of course was not exposed. On my local Linux I changed CXF endpoint to and everything was working like a charm, but when I ran my Camel route I got address already in use error. I had to explicitly use the $OPENSHIFT_INTERNAL_IP variable to define the IP address.


After I finish my 0.0.5-SNAPSHOT development I definitely will try to setup all Qualitas modules on OpenShift! Stay tuned!


The Cloud Zone is brought to you in partnership with Mendix. Better understand the aPaaS landscape and how the right platform can accelerate your software delivery cadence and capacity with the Gartner 2015 Magic Quadrant for Enterprise Application Platform as a Service.


Published at DZone with permission of Łukasz Budnik , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}