Selecting a Code Generator: Tools for generating Java application code

On several occasions over the last few years I’ve thought ‘hmm, wouldn’t it save time if we could generate this code from xyz’, and in some cases I’ve written my own code generators using template engines such as Velocity.

The pages in all the web applications I’ve worked on always follow a well defined set of project standards and implement a slice across defined architectural layers. In most cases, it would also be easy to generate skeleton code that implements the standard Create/Retrieve/Update/Delete (CRUD) functionality using code for each of the layers in the application.

I have a new project to build an online store that I’m currently thinking about. The great thing about ‘green-field’ projects is that it’s a great opportunity to start with something new – new technologies and new methods. This application is going to have typical CRUD pages for each of the entities involved, so rather than writing Entities, DAOs, Business Logic, and MVC style front end from scratch, I’ve been thinking and looking at the options out there for generating the code.

The first option would be to generate a skeleton app using AppFuse. Although not entirely what I’m looking for, at least this would generate the skeleton code complete with project layout and build scripts for the technologies that I choose.

The other options are tools that generate code from either UML models or existing DB schemas. The first that keeps coming to the top of my Google results is JAG – Java Application Generator. This looks like a promising tool. I’ve been meaning to download this and give it a go – it generates a working web app with CRUD functionality from an exported UML model in XMI format, using Hibernate, EJB2.1/3 and Struts. The only thing that is currently putting me off is that the frontend is using Struts. Given this current opportunity to start with a clean slate for this new app, I would not pick Struts for the web tier, since Struts lifespan is seriously limited at this point with JSF as the new kid in town.

Other generation tools I’m considering: JBoss Eclipse IDE have a CRUD generator that generates a skeleton app using their new Seam framework, using JSF and EJB3.0. This is currently the most attractive option, but I’m not too excited about the JBoss Eclipse IDE. The last time I used it (1.5) a couple of months ago everthing was great, apart from the hideous packaging interface for building the dependencies between projects as Jars, WARs and EARs. Having lived in the IBM WSAD/RAD world for the past couple of years, this part of the tool in comparison to what I’ve been used to really was lame. I even showed one of my colleagues and he just laughed. Anyway, JBoss have a demo Flash movie on their site of the generation part of the IDE, which looks interesting.

The other option which initially looked very promising was the ‘JSF Pages from Entity’ generator option in Netbeans 5.5. I say this in the past tense because I’ve tried it out, ran into exceptions in the wizard, and when I finally did get it to work, it would not deploy on JBoss 4.0, which will be my target platform. This is a great shame because this was the most attractive so far, but if it doesn’t work then it’s no good to me.

I haven’t chosen any solution yet, but I’ll post an update once I’ve investigated some of these options further and come up with a direction to go with.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.