One of the cool features of deploying a Java project on OpenShift Express is that you can deploy a web application without having to build it locally and then adding the war file to the Express Git repository. The primary benefit of doing this is that it conserves application disk space over subsequent deployments. Because a war file is binary, each time you commit a new version to the Git repository, the incremental disk space used to support the new version is the same as the size of the war file. So if my war file is 5mb, each time I commit a new version, the size of my Express application increases by 5mb (plus or minus depending on what has been added/removed from my app).
With source deployments, if my source code is 100k (remember, source is text), and my pom.xml (Maven build file) is setup properly, my project will be built server side and deployed when JBoss starts. Deployments that are built on the server are not committed to the Git repository so each time I edit source and redeploy, I’m only increasing the size of my repository by the size of the diff of my code. As you can probably imagine, this will help prevent my application from quickly reaching the quota of Express applications.
The steps for configuring a maven project to build server side are quite simple. Using the ‘kitchensink’ sample app that is available from the JBoss Application Server 7 downloads page, I’ll walk through making the required changes to support server side building.
In order to deploy an OpenShift application, one must first be created:
rhc-create-app -a kitchensink -t jbossas-7.0
We’ll remove the stock application so we can copy over our ‘kitchensink’ app:
cd kitchensink<br />git rm -rf pom.xml src
You can download the ‘kitchensink’ application from the ‘Quick Starts’ from http://www.jboss.org/jbossas/downloads/ and extract it somewhere on your computer. The path might be something like /home/[username]/Downloads/jboss-as-quickstarts-7.0.0.Final/kitchensink (we’ll call it SOURCE below):
cp -R SOURCE/kitchensink/pom.xml .<br />cp -R SOURCE/kitchensink/src .
Before committing/pushing this application, we have to add a Maven profile called ‘openshift’ so that the project gets built properly. Maven support passing in the profile on the command line and this is what OpenShift Express does when it detects a pom.xml file in your Git repository. We’ll edit ‘pom.xml’ and add the following to the end just before </profiles>:
<profile><br /> <!-- When built in OpenShift the 'openshift' profile will be used when<br /> invoking mvn. --><br /> <!-- Use this profile for any OpenShift specific customization your app<br /> will need. --><br /> <!-- By default that is to put the resulting archive into the 'deployments'<br /> folder. --><br /> <!-- <a href="http://maven.apache.org/guides/mini/guide-building-for-different-environments.html" title="http://maven.apache.org/guides/mini/guide-building-for-different-environments.html">http://maven.apache.org/guides/mini/guide-building-for-different-environ...</a> --><br /> <id>openshift</id><br /> <build><br /> <finalName>tweetstream</finalName><br /> <plugins><br /> <plugin><br /> <artifactId>maven-war-plugin</artifactId><br /> <version>2.1.1</version><br /> <configuration><br /> <outputDirectory>deployments</outputDirectory><br /> <warName>ROOT</warName><br /> </configuration><br /> </plugin><br /> </plugins><br /> </build><br /> </profile>
Now that OpenShift will be able to run the ‘openshift’ profile at build time, we’re ready to add, commit, and push the code.
git add –A<br />git commit -a -m "first deployment of Kitchensink"<br />git push
What will happen at this step is your code will be pushed up to the OpenShift Express cloud, OpenShift will detect your pom.xml, a Maven build will be executed (mvn clean package -Popenshift -DskipTests), and assuming that the build is successful JBoss AS 7 will be started and your server side built war file deployed.
If you use the Kitchensink example, you should see the following when you browse to http://kitchensink-[domain].rhlcoud.com