XDoclet Tutorial

XDoclet is a toolset built on top of the Javadoc annotation mechanism. The XDoclet toolset is an open source project, currently managed on SourceForge. Essentially, XDoclet provides a suite of predefined custom Javadoc tags designed for use in various development scenarios, such as developing web and EJB components, implementing web services, integrating Hibernate persistence management, deploying components to specific application servers, and so on. Annotating your code is done using these Javadoc tags within code comments. XDoclet includes a set of Ant tasks that are used in your buildfiles to process the annotations and generate the appropriate outputs.

Annotating Your Code

XDoclet annotations can be applied to specific entities in your Java code:

  • Classes or interfaces

  • Methods and constructors

  • Member variables

These annotations look a lot like standard Javadoc comments. The general syntax for XDoclet annotations is:

@tag-group.tag-name param1="value1" param2="value2"

The tags are organized into groups, indicated by the tag-group label, and each tag has a unique name within its group, indicated by the tag-name. A tag can optionally accept one or more parameters, which are provided in the annotation using the syntax shown here. You can also put parameters on lines following the tag line. The XDoclet processor will consider all subsequent parameter lines to belong to the initial tag you specify. So the previous example could also be put into your code as:

@tag-group.tag-name ...

Get Java Enterprise in a Nutshell, Third Edition 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.