Towards Java EE Nirvana
Java EE 6 makes it pretty straightforward to crunch out a basic web +
database application. This semester, my software engineering class is building
web apps, and I decided it is simpler to have them use JSF + JPA in Glassfish
v3 rather than some technology that seems easy at first and then lets them
down.
Here is a laundry list of recent simplifications.
- Author JSF pages as facelets: XHTML + JSF tags. No icky JSP syntax
- Use annotations:
@ManagedBean @Stateless @Entity @EJB
@PersistenceContext
. No icky XML configuration
- Use EZNavigation™ in JSF. Actions directly return the view ID
string. Hooray—no navigation in
faces-config.xml
- No more busywork interfaces for session beans
- Use entity annotations, and let JPA generate the tables. No SQL!
- Package everything
in a single WAR
The WAR file has the structure
web pages (.xhtml)
WEB-INF/
web.xml
faces-config.xml
classes/
managed beans
stateless session beans
entity beans
META-INF/
persistence.xml
There are three cookie-cutter XML files that you never need to touch. In
particular, faces-config.xml
is empty! The rest is XHTML and Java.
Unfortunately, setting up your tools is a bit of trouble because everything
is right now a moving target. Here are the steps.
- Install Glassfish
v3 Prelude
- Add the glassfish-v3-prelude-version/glassfish/bin directory to
your PATH
- Run glassfish-v3-prelude-version/updatetool/updatetool. Add the
Glassfish EJB container. Install any available updates.
- Check the version of the JSF 2.0 implementation in the updatetool. If it
is ≤ 2.0.0.8, download the JSF
2.0 Nightly build; pick mojarra-2.0.0-SNAPSHOT-binary.zip and replace
glassfish-v3-prelude-version/modules/jsf-api.jar and
glassfish-v3-prelude-version/modules/web/jsf-impl.jar with the
versions in that zip file.
- Start the server:
asadmin start-database
asadmin start-domain
- Download and unzip this test application.
Edit
build.properties
and set the path of your Glassfish
installation. Run ant
. Point your browser to
http://localhost:8080/SimpleQuiz

- You can use the EE version of Netbeans 6.5 out of the box. With the EE
version of Eclipse 3.4, install the Eclipse
Glassfish adapter . When you import the sample project into Eclipse,
make a “Dynamic web project”, set the source path to
src/java
(not src
), the web path to
web
(not WebContent
), and uncheck “Generate
deployment descriptor” . Both Netbeans and Eclipse do a beautiful job
with hotswapping.
Overall, I was very
happy. This is a huge step forward from five years ago, when Bruce Tate refused
to eat
Elephant again.
Have we reached Nirvana? Not quite. Here are some remaining hassles:
- I hate writing (and reading) all those getters and setters. Did I ever
mention that Java needs
support for properties?
- For a simple app, it is a nuisance to separate managed beans and session
beans. Web beans, erm, Java
Contexts and Dependency Injection, should solve that, but I didn't have
the courage to throw that into the mix. Next semester :-)
- Error reporting has become better, in no small part thanks to facelets.
But I still get the stack
trace from hell more often than I'd like.