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
Here is a laundry list of recent simplifications.
- Author JSF pages as facelets: XHTML + JSF tags. No icky JSP syntax
- Use annotations:
. No icky XML configuration
@ManagedBean @Stateless @Entity @EJB
- Use EZNavigation™ in JSF. Actions directly return the view ID
string. Hooray—no navigation in
- No more busywork interfaces for session beans
- Use entity annotations, and let JPA generate the tables. No SQL!
in a single WAR
The WAR file has the structure
web pages (.xhtml)
stateless session beans
There are three cookie-cutter XML files that you never need to touch. In
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.
- Add the glassfish-v3-prelude-version/glassfish/bin directory to
- Run glassfish-v3-prelude-version/updatetool/updatetool. Add the
Glassfish EJB container. Install any available updates.
- Check the version of the JSF implementation in the updatetool. If it
is < 2.0, delete it and go back to the list of available modules. You should get a 2.0 module that you can install. You need version 188.8.131.52 or above.
- Start the server:
- Download and unzip
href="http://horstmann.com/elvis/SimpleQuiz.zip">this test application.
build.propertiesand set the path of your Glassfish
ant. Point your browser to
- You can use the EE version of Netbeans 6.5 out of the box. With the EE
version of Eclipse 3.4, install the href="http://weblogs.java.net/blog/arungupta/archive/2008/05/glassfish_v3_tp.html">Eclipse
Glassfish adapter . When you import the sample project into Eclipse,
make a “Dynamic web project”, set the source path to
src), the web path to
WebContent), and uncheck “Generate
deployment descriptor” . Both Netbeans and Eclipse do a beautiful job
Overall, I was very
happy. This is a huge step forward from five years ago, when Bruce Tate refused
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 href="http://weblogs.java.net/blog/cayhorstmann/archive/2006/06/say_no_to_prope.html">needs
support for properties?
- For a simple app, it is a nuisance to separate managed beans and session
beans. Web beans, erm, href="http://in.relation.to/tag/Java+Contexts+and+Dependency+Injection">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 href="http://weblogs.java.net/blog/cayhorstmann/archive/2006/09/the_power_and_p.html">stack
trace from hell more often than I'd like.