Java EE6 running in JBoss AS7 brings a lot of new interesting technology to the table. It provides the capabilities of EJB via a dependency injection model with a ton of simplifications. Think Ruby on Rails simplicity coupled with the power of Java EE… Add to that OpenShift’s ability to build and deploy code server side and you can start writing an EE6 CDI application with the ease of writing a PHP or Rails application. The syntax is even simplied to the point where I am actually able to get a decent amount of work done in vim. Don’t believe me? Well, walk through an example with me and I’ll let you decide for yourself.
Also, if you would rather watch a screencast of this post, check out Pete Muir’s screencast on the topic:
Step 1. Register on OpenShift
A free account on OpenShift will provide you with a free runtime environment for this demo. Yep, a free EE6 runtime environment that is pubicly accessible. Cool, huh? First, signup for a new account. You’ll need to validate your email address after registering – just click the link in the email you get. After that, you should get an email once you have been granted access. Should be quick – we are sending people through as fast as we can.
For some help setting up the client tools, you can check out the following screencasts that walk you through the process for various operating systems:
Step 2. Create your domain
A domain will be used in your url. I wanted http://<app>-oncloud.rhcloud.com so I ran:
rhc-create-domain -n oncloud -l <my-email>
Step 3. Create a JBoss application template
I want my URL to be http://seamrocks-oncloud.rhcloud.com so I ran:
rhc-create-app -a seamrocks -t jbossas-7.0
At this point, you will have our ‘Hello World’ application running. It’s a very simple, Maven-based application. You will see a pom.xml that specifies how to build and deploy the application as well as a ‘src’ directory that contains the application structure.
Step 4. Switch your application to the Seam Booking Quickstart
We maintain a lot of OpenShift quickstart applications out on GitHub. This gives people an easy way to get fairly sophisticated applications running in minutes. Here is how to get the Seam Booking example running (also documented in the GitHub readme):
git remote add upstream -m master git://github.com/openshift/seambooking-example.git
git pull -s recursive -X theirs upstream master
For OpenShift deployments, a new Maven ‘profile’ is added the pom.xml file that is used on deployment. This profile sets the deployed war as ROOT.war to load it in the default context and also gives it any packaging or build tips for the specific app.
Step 5. Wait for it…
Now is where the really cool part happens. You just pushed up a bunch of Java source file with a POM file. OpenShift will detect this and automatically kick off your Maven build. Be warned, downloading all the dependencies and doing the build will take about 20 minutes the first time you build. After the dependencies are downloaded, subsequent builds just take seconds. Kick back, grab a cup of coffee and wonder what you are going to do with that old build system…
When the build is done, your application will be automatically deployed and running. In my case, that application is running at:
Step 6. Fire up your text editor
That’s right – let’s actually do some Java editing with just a text editor! To keep this simple, we will just change something that requires a new build to be visible. You could just as easily change a JSF template, or one of the Java files – it all works the same. In this case, we are going to change the message bundle to put our mark on the demo app.
Open up your favorite editor and load the file src/main/resources/messages.properties
Next, change the following text in the file:
home_header=About this example application
Now save the file and close it. Lastly, let’s commit and push the change:
git commit -a -m “Making my mark”
One gotcha is that is that while JBoss is deploying, an error response (e.g. 503) can sometimes be cached at our proxy and you’ll see an erroneous error when you hit your app in the browser. We’re working on correcting this but in the meantime, if you hit it just run:
rhc-ctl-app -a <app> -c restart
Also, if something strange is happening, you can always tail the server logs with:
rhc-tail-files -a <app>