1.8. Generating Struts Configuration Files Using XDoclet
Problem
When you make changes to or create a new
Action
or ActionForm, you have to make the corresponding
changes to Struts configuration files.
Solution
Use the XDoclet tool, in conjunction with Ant, to process annotations in your Java code for automatic generation of the struts-config.xml file.
Discussion
Modern software applications are commonly composed of executable code as well as text configuration files. This approach makes it easier to port your application between environments and reduces the amount of code you have to change for different deployments. However, it adds an additional burden: keeping the code and the configuration files consistent with each other.
The XDoclet tool, originally developed for use in Enterprise JavaBean development, addresses this problem. With XDoclet, the developer places annotations, similar to JavaDoc tags, in the code that describes configuration attributes related to the code. At build time, you employ custom Ant tasks that use XDoclet to process these tags and generate the corresponding XML configuration files.
For Struts, XDoclet can generate the following elements for the struts-config.xml file:
actionelementsform-beanelements
In addition, XDoclet can
create the
field-level Struts Validator configuration, typically found in the
validation.xml file. Finally, if you are mapping
properties of EJB Entity Beans to Struts
ActionForms, XDoclet can generate the
ActionForm Java source ...