Code Generation

JAM supports both XDoclet and UML-based code generation via the standard gen target.

XDoclet

XDoclet is invoked by default in the gen standard target to generate various J2EE deployment descriptors and support classes. XDoclet output is treated as build artifacts. In other words, each time you do a clean build, all XDoclet output is regenerated. To remove XDoclet calls simply override the gen target and remove the xdoclet target from the depends clause. Likewise, to modify the XDoclet call, override the xdoclet support target or write your own and include it in the depends clause of the your overridden gen target.

UML Code Generation Support

UML-based code generation is supported through the use of dual source directories: src and src-gen. Code found in the src-gen directory has the following characteristics:

  • This source is compiled and packaged alongside code found in the src directory.
  • When duplicate source files exist in both src and src-gen, the copy found in src-gen is moved to a backup directory.
  • You can force regeneration of this code by typing ant clean.gen
  • When using JavaGen, src-gen code is regenerated automatically whenever the UML file is modified.

If you need to modify a file in src-gen, move it to src so it will not be overwritten on subsequent regeneration cycles.

JavaGen Code Generator

JavaGen is a sophisticated J2EE UML-based code generator with a very capable, freely available community edition. JavaGen generates EJB and webapp code, including XDoclet tags based on the application server and database you are using. The web service interface of JavaGen can be added to your build by importing the JavaGen module:

<import file="${jam.home}/javagen-ws.xml"/> 

And then adding the javagen dependency to the gen target. In the case of an EJB project the overridden gen target would look something like this:

<target name="gen" depends="init, javagen, ejbdoclet"/> 

Removing the src-gen Directory

If you are not using the src-gen directory, it can be hidden from view by placing the following property definition at the top of your build file:

<property name="gen.src.folder" value="target/noop-src-gen"/>