GWT and EJB 3.1

Recently we have been tasked with building a rich, complex web application for resource planning. Historically most of our applications have been successfully delivered using Rails. However the cost of developing rich applications has been significant and only a few developers are comfortable working with low-level javascript frameworks.

We prototyped the front-end using ExtJS and were looking at implementing the backend technology using EJB 3.1 beans (See Why EJB? for our reasoning). We investigated using JSF and GWT as the front end technology but eventually settled on GWT, took a course and went through a number of labs to develop a simple GWT application.

The course only gave us a taste of GWT and we still needed to do a bunch of investigation to get a GWT application from "toy" stage to production ready. We took the best practices MVP example and started to evolve it towards an archetypal example in our world. This involved adding an automated build system that we could run from our CI box, moving to EJBs for the service layer, JPA for the persistence layer, moving to Intellij IDEA for the IDE and splitting the project out into multiple components that could be worked on independently.

The code for converting the service layer to EJBs was actually quite simple as is evidenced by the commit. However this code does not work in the built-in Jetty container used as part of development mode. The documentation on how to actually use EJBs is rather thin. In Intellij IDEA, this entailed setting up the IDE to build an exploded war, configuring GlassFish support and passing -noserver to the GWT plugin.

For the build system we initially trialled using Maven 3.0.3 but went back to using Apache Buildr. Maven is a project I want to like and has great ideas but even years after it was developed I keep running into stability issues; plugins don't work, dependencies are not locked by default etc. Buildr is a little rough around the edges but does not get in your way when you want to do something custom. The commit that converted the project to buildr is a perfect example. There is very little code involved in the Buildr files buildfile and build.yaml but there is a fair amount of custom code involved in modifying the Intellij IDEA buildr extension so that it generates custom metadata for the build. Admittedly these customizations will be rolled back into Buildr over time but it was simple to extend core Buildr classes to achieve our immediate needs.

Separating the different elements of the application out into separate components proved to be a minor annoyance. The code remained unchanged but the build system had to be refactored significantly as did the Buildr customizations to generate the IDEA project files. However, you can see a snapshot of the current work in progress on github project at the tag BLOG_POST.


Why EJB?

We need to integrate with a thick Swing client over a custom network protocol and a web portal & BPMS using SOAP web services as well as the front-end for our new application. Candidate service layers included OSGi, Spring and EJB 3.1. Bizarrely enough we chose EJBs because it was simpler (!!!) to provide these interfaces in the straight JEE stack. (And yes we were very surprised to come to that conclusion too!).

GWT Course

The course was delivered by Adam Jenkins at Object Training and it was quite good. About the only complaint I have was that some of the architectural labs and talks were too focused on mechanical aspects and did not make the reasons for selecting a particular architecture clear. I came away thinking that the GWT MVP design pattern was developed by architecture astronauts but after reading more and watching a few YouTube clips I am sold on the approach.