JAM Setup

The JAM (JavaGen Ant Modules) build framework, originally tightly coupled to JavaGen, was spun-off into a stand-alone open-source product. It is a sophisticated and very capable Ant framework with many high-level features borrowed from Maven. Regardless of weather or not you use JavaGen, if your doing serious test-driven Java/J2EE development, you should have a look at JAM.

JAM automatically triggers regenerating when UML changes are made. Furthermore, JAM will manage duplicate source files, generate XDoclet support classes and deployment descriptors, in addition to automating many other J2EE deployment and testing tasks.

build.xml Example

A typical JavaGen build file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project name="javagen-autopk-ejb" default="default" basedir=".">
	<property environment="env"/>
	<property name="jam.home" location="${env.JAM_HOME}"/>
	<property name="model.path" value="${basedir}/src/uml/javagen-autopk-ejb.zuml!/*.xmi"/>
	<!-- ===================================================================== -->
	<!-- import properties and ant modules -->
	<!-- ===================================================================== -->
	<import file="${basedir}/src/jam/props-maven.xml"/>
	<import file="${basedir}/src/jam/props-javagen.xml"/>
	<import file="${jam.home}/props-global.xml"/>
	<import file="${basedir}/src/jam/classpath.xml"/>
	<import file="${jam.home}/appserver-jboss3.xml"/>
	<import file="${jam.home}/ejb.xml"/>
	<import file="${jam.home}/javagen-ws.xml"/>
	<!-- =================================================================== -->
	<!-- Override public targets: -->
	<!-- =================================================================== -->
	<target name="gen" depends="init, javagen, ejbdoclet" description="override to invoke javagen"/>
	...
</project>

This example generates an EJB domain tier. The relevant lines are:

<property name="model.path" value="${basedir}/src/uml/javagen-autopk-ejb.zuml!/*.xmi"/>

The model.path property indicates the location of the UML model. Because the zuml file is actually a zip archive, the /*.xmi following the ! character specifies the file to locate within the archive. In this case a wildcard (*) is used to indicate JavaGen should find the file ending with xmi.

The next line of interest is:

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

which imports the JavaGen web service module and

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

which adds the javagen task to the depends clause, so JavaGen will be triggered early in the build process automatically whenever the UML file is changed.

props-javagen.xml

Optionally you can keep your JavaGen settings in a separate property file. The JavaGen examples all use a file named props-javagen.xml. This file controls which modules are invoked, sets module-specific and global properties.

<?xml version="1.0" encoding="UTF-8"?>
<project name="props-javagen">
	<!-- ===================================================================== -->
	<!-- code generation switches -->
	<!-- ===================================================================== -->
	<property name="javagen.ejb.flag" value="true"/>
	<property name="javagen.sql.flag" value="true"/>
	<property name="javagen.unittest.flag" value="true"/>
	<!--
	<property name="javagen.struts.flag" value="true"/>
	<property name="javagen.struts.no-form.flag" value="true"/>
	<property name="javagen.struts.no-session.flag" value="true"/>
	<property name="javagen.struts.no-jsp.flag" value="true"/>
	<property name="javagen.struts.no-action.flag" value="true"/>
	-->
	<!-- ===================================================================== -->
	<!-- JavaGen code generator control properties: -->
	<!-- ===================================================================== -->
	<!-- comma delineated list of target application servers: 
	jboss3, jboss4, resin2, resin3, weblogic8, websphere, oracle9
	-->
	<property name="javagen.servers" value="jboss3"/>
</project>

javagen-ws.xml

This file contains various tasks for invoking JavaGen as a web service. The 'javagen' target is the only public target and is usually invoked in JAM's 'gen' target before XDoclet is invoked (see the example above).

TODO: document javagen Ant task