In this short blog, I will show you how you can deploy war file on Tomcat running on OpenShift. For Java, OpenShift supports three deployment options – JbossAS-7, JBossEAP-6, and JBossEWS-1.0 or Tomcat. In all of the three options it supports both binary deployment (war file) and source code deployment(maven project). I have talked about how you can do source code deployment on tomcat in my previous blog.
Step 1: Sign up for an OpenShift Account
If you don’t already have an OpenShift account, head on over to the website and signup with promo code ews. It is completely free and Red Hat gives every user three free Gears on which to run your applications. At the time of this writing, the combined resources allocated for each user is 1.5 GB of memory and 3 GB of disk space.
Step 2: Install the client tools on your machine
Note: If you would rather watch a screencast of this step, check out the following videos where I demo how to install the client tools.
The OpenShift client tools are written in a very popular programming language called Ruby. With OSX 10.6 or later and most Linux distributions, ruby is installed by default so installing the client tools is a snap. Simply issue the following command on your terminal application:
sudo gem install rhc
Step 3 : Setting up OpenShift
The rhc client tool makes it very easy to setup your openshift instance with ssh keys, git and your applications namespace. The namespace is a unique name per user which becomes part of your application url. For example, if your namespace is cix and application name is bookshop then url of the application will be https://bookshop-cix.rhcloud.com/. The command is shown below.
rhc setup -l openshift_login
Step 4 : Creating Tomcat Application
After installing the client tools and setting up OpenShift account, next step is to create the bookshop application. This is a very simple Spring JPA application which has only one entity called Book. So, a user can do CRUD operations on book entity. To create a book entity, execute the command shown below.
rhc app create -a bookshop -t jbossews-1.0
This will create an application container for us, called a gear, and setup all of the required SELinux policies and cgroup configuration. OpenShift will also setup a private git repository for you and propagate your DNS out world wide.
Step 5 : Download the WAR file
Because we are doing binary deployment in this blog, we have to remove the src folder and pom.xml file from git repository and add the war file.
git rm -rf src/ pom.xml git commit -am &quot;removing default files&quot;
Next download the war file from http://bookshop-demo.googlecode.com/files/ROOT.war and copy the war file in webapps directory. The name ROOT for war makes sure that the application is accessible at the root context i.e. http://bookshop-cix.rhcloud.com/.
git add . git commit -am &quot;committing bookshop war file&quot;
Step 6 : Pushing the code to OpenShift
Finally push the code to OpenShift using git.
The git push command upload the binary to the application gear and runs the action hooks specified in .openshift/action_hooks folder.
5 thoughts on “Deploy war on tomcat running on OpenShift”
I followed these instructions and tried deploying my WAR on openshift tomcat7 and ran into issues, which I have detailed in this forum https://openshift.redhat.com/community/forums/openshift/groovy-servlet-crashes-trying-to-create-a-file-in-servlet-temp-directory#comment-27747
Would you have any suggestions ?
I started afresh using these instructions – https://github.com/openshift/openshift-tomcat-quickstart
I now have my app running on Tomcat, after I uploaded the WAR using the manager app on Tomcat.
The problem earlier was that I was using Jboss EWS 2.0 since it was labeled Tomcat 7.
how about fetch the code from the openshift server instead of transferring war? but seems compiling requires more memory and can make server expensive to rent.
I have deployed my Tomcat 7 (JBoss EWS 2.0) application on Openshift. Now when am redeploying it with some changes in the source code, the changes are not refelcting in my site. I deployed the WAR file. I have been trying hard for like 1 week but not able to do it. I am able to see the changed files in the repo. But the changes are not reflected in the site. Please Help!!!!