Thursday, January 22, 2015

How To: Deploy a Java war file to OpenShift

I recently put together a responsive web application for someone that wanted a convenient way to keep track of the types of food they've had each day with the ability to perform some statistical analysis on the data recorded. The application uses Spring, Hibernate, JSF, Primefaces, and Twitter Bootstrap. They've opted to have it hosted in the cloud using Red Hat's OpenShift which gave me an opportunity to use the platform for the first time.

Openshift provide a range of options for Java. My app needed Java 7 and Tomcat 7 (there currently doesn't seem to be an option for Java 8) so I selected the appropriate option and set about getting my app deployed.
$ git clone
$ cd nutritionapp/
A directory structure and pom file is already setup for those wanting to commit source code to be built by Openshift prior to deployment. This wasn't what I wanted as I've already compiled a war file and just want a quick way to deploy it. For this option, Red Hat have also put a 'webapps' folder in the root of the repository so I needed to do was delete the 'pom.xml' and the 'src' folder, add the war then push.
$ git rm pom.xml
$ git rm -r src/
$ git add webapps/nutritionapp-1.1.war
$ git commit -am "deploy v0.1 to cloud"
$ git push
I then ssh'd into OpenShift using the url provided in the web interface and did 'tail -f app-root/logs/jbossews.log' to see what was happening with deployment. There was a problem during start up but the log entry wasn't too helpful. Luckily I found a post here which helped out, seems that in OpenShift the 'web.xml' in the app needs to have the Log4jConfigListener removed.

So after a quick edit of the 'web.xml' one last commit was needed.
$ git commit -am "removing Log4jConfigListener"
$ git push
That was it, the whole process was pretty simple.

No comments: