JAXB class generation using Maven

There is a useful maven plugin to generate all our JAXB classes for us. This plugin can be executed during the generate-sources phase of our maven build. It can be very useful, especially in the first stages of our project when the design of our XSD may change frequently.

We can just add the plugin configuration to the pom.xml of our project.

We can use the Fluent Api plugin to provide method chaining for bean setter, which makes it easier for us to create bean instances . See: http://java.net/projects/jaxb2-commons/pages/Fluent-api. To customize our JAXB generation we specify a bindingdirectory. In this bindingdirectory we can put a .xjb file which contains our specific JAXB generation settings.

In the jxb:bindings schemaLocation we refer to our xsd file as source for our generated JAXB classes. To specify the package prefix we can use the jxb:package tag . We can use the jxb:nameXmlTransform tag to customize the name of our (anonymous) types.

Leave a Reply

Your email address will not be published. Required fields are marked *