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: 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.

<jxb:bindings version="1.0"

    <jxb:bindings schemaLocation="OurTestXsd.xsd" node="/xs:schema">
        <jxb:package name="nl.jdriven.sample.domain">
        <jxb:typeName prefix="XML"/>
        <jxb:anonymousTypeName prefix="XML"/>

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.