XBean Ant Task
XBean provides an Ant task of type org.apache.xbean.spring.task.SchemaGenerateTask which auto-generates the following files
- the META-INF/services/org/apache/xbean properties file for your XML configuration
- a HTML reference documentation for your XML using javadoc comments and/or annotations to extract the descriptions
- an XSD for your XML configuration (currently under development - it needs a little bit of work)
How it works
The Ant task is using Annogen or to be exact, JAM to process each class in your build which then looks for the XBean annotation (or doclet tag) to find all the POJOs in your application which you want to include in your XML language.
Configuring the task in Ant or Maven
Here's an example of the use of the task in a maven build.
In particular here are the Ant properties of interest.
Property Name |
Description |
namespace |
The namespace URI to use by default on your XBean's if you have not specified it inside your source code. Typically all of your beans will go into the same namespace so its often easier to put it in the Ant task and not in your code |
srcDir |
The directory where your source code resides |
metaInfDir |
The directory the META-INF/services files will be auto-generated. In some IDEs its often better to put those in a different place to your build |
classpathref |
the classpath to use |
destFile |
The destination XSD to generate |
XBean annotation guidelines
Any POJO you wish to turn into an XML element in your configuration file syntax, add an XBean annotation. If you don't like the default name auto-generated by XBean then add an *element="myName" property. e.g.
/**
* @org.apache.xbean.XBean
*/
class Cheese {
}
or
/**
* @org.apache.xbean.XBean element="cheese-flavour"
*/
class Cheese {
}
For the root element in your language add rootElement="true"
The generated documentation generally uses the doclet comments from your code. e.g. the comment on setter methods or on classes. If you wish to provide a custom XML-editor friendly version of the comments, use a description="..." value on the annotation.
XBean will then autogenerate
- the file in META-INF/services/org/apache/xbean which is used by XBean to auto-discover your new XML language.
- the XSD you can use to validate your XML
- a HTML reference document.