Deploying a NinjaFramework Application on OpenShift

Deploy a fat jar to OpenShift… Hmmmmm

A NinjaFramework application is built and deployed as a fat jar by default. Given this fact, I popped this question on StackOverflow. I figured that one would need to be some kind of Maven guru in order to build some kind of configuration to deploy it on OpenShift. Not so as it turns out. The guys at NinjaFramework have once again come up trumps. It turns out the process is effortless. This blog describes the steps involved from beginning to end. This process uses Netbeans.

Setting things up

Follow the steps to getting started as described here on the OpenShift website.

Install ALL the client tools and perform all the steps.

I found it necessary to set the (Windows) %HOME% environment variable. Set it to something like C:\Users\John, its natural place. Without this, I found some of the processes and applications used throughout were referencing different locations which was problematic to say the least.

Next up, create the OpenShift application on the OpenShift website itself. I created a Tomcat 7 (JBoss EWS 2.0) application.

On Netbeans, clone the git repository

The URL for the git repository can be found here on OpenShift

Follow the prompts and checkout the default project.

At this point it might be best to use your initiative and do whatever you think is best but I did the following:

Created a NinjaFramework default project from the Archetype

Follow the wizard through to generate the project.

I pretty much copied each folder from the NinjaFramework project into the existing project, I deleted the .html and .jsp files. The End result looks like this:

Next up, the POM file. I copied the ‘properties’, ‘build’ and ‘dependencies’ from the NinjaFramewok project into the OpenSift project:

At this point the project is ready to go. Run it in Superdev mode using the technique described here or just launch it in Jetty using the Maven ‘jetty run’ goal

In either case, the browser is not automatically launched. You just need to navigate to http://localhost:8080 to see the application.

Anyway, if you’re here it’s likely that you know all that stuff anyway but I figure it’s no harm to be thorough.

Assuming the application runs, you’re good to go with deploying it to OpenShift

Deploying to OpenShift

Be sure to add %prod properties to application.conf because OpenShift will run in production mode and therefore will expect them

This is the only no-so-ideal part of of the process but hey, it’s not bad either. Reverse the commenting in the POM file from:

To

So basically, this will now enable a war file to be generated. Simply hit run (or debug) in Netbeans…

You’ll be prompted for an application server

Select the server and hit ok to launch the application.

An obvious problem is revealed here. The /contextpath part of the http://localhost:8084/contextpath part of the application URL throws off all the CSS, JS resources URL’s. All of the links are also wrong because they don’t account for the context path. This is a trivial issue, don’t give it a second thought for now.

You’re now ready to deploy to OpenShift.

Commit the project to git

When committed, remote – push the project to OpenShift

In OpenShift the status of the project will change to ‘Building’ then back to ‘Started’

The application should now be ready….

Conclusion

This tutorial has articulated in simple steps how to get a NinjaFramework application deployed and running on OpenShift.

Each of the steps are critical, so if it’s not working out look back over the steps.

Feel perfectly free to pop any questions here. I’m no expert on this kind of stuff but I figured it was worth sharing what little I do know about it anyway. So, with that in mind, efficiencies, corrections and successes are welcome as comments.

Once again, I’m in awe of the Ninjaframework. It’s a joy to work with compared to other frameworks due to the simple reason that everything required for most applications is just there and it just works without hassle.