Setting Up Ant to Run XDoclet

Problem

You want to integrate file generation into the Ant build process.

Solution

Modify your Ant buildfile to create the directory structure as specified in the previous recipe and execute an xdoclet.DocletTask or subclass. This recipe creates a task definition for xdoclet.modules.ejb.EjbDocletTask and names it ejbdoclet.

Discussion

A successful XP project understands the need for continuous integration. Continuous integration means a successful build of the project, including complete generation of all out-of-date generated files and 100% passing unit tests. With that said, here’s how generating source files improves the continuous integration process. Here is a typical Ant build process:

  1. Prepare the development environment by creating output directories.

  2. Compile out-of-date code.

  3. Package the code into a deployable unit (JAR, WAR, or EAR).

  4. Execute the JUnit tests.[42]

  5. Deploy to a server.

If any task fails the build should stop and a friendly message should be reported. Code generation adds one more step to this process:

  1. Prepare the development environment by creating output directories.

  2. Run XDoclet to regenerate out-of-date generated source files.

  3. Compile out-of-date code.

  4. Package the code into a deployable unit (JAR, WAR, or EAR).

  5. Execute the JUnit tests.

  6. Deploy to a server.

Adding the code-generation step requires modifying the Ant buildfile. The first step is to define a task definition for an xdoclet.DocletTask task. This recipe uses the xdoclet.modules.ejb.EjbDocletTask ...

Get Java Extreme Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.