• Code generation from XSD with JAXB and Maven


    What you will learn in this small post

    • How to create JAXB proxies at build time using maven-jaxb2-plugin in a continuous build environment (TeamCity / Bamboo)
    • How to generate from an XSD file (XML-Schema-Definitions) Java code.


    • We will use JAXB2 (see JSR 222 and JAXB 2.x).
    • We use Maven 2.2.1, the latest available version

    Settings things up

    The only difficulties is to add to your Maven proxy (Archiva, artifactory) the Maven repository of Sun. The example below use an inline repositories definition in pom.xml. So it work out of the box.

          <name> Maven 2 Repository</name>

    and the special Sun Maven plugin repository


    Here is how your pom should look like

    <project xmlns= xmlns:xsi=""
          <name> Maven 2 Repository</name>
    <pluginRepositories> <pluginRepository> <id></id> <name> Maven 2 Repository</name> <url></url> </pluginRepository> </pluginRepositories>

    All you have to do now is to place your XSD shema in src/main/resources and run mvn package

    The JAXB proxies will be created in target\generated-sources\xjc\generated so you can use them in src/main/java and src/test/java