Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

Generating Java classes from an XSD is a common use case. I am partial to the Highsource (e.g. jvnet) maven-jaxb2-plugin. This plugin is very easy to use. Add the following to your pom.xml.


By default, the plugin will compile any xsd files located in src/main/resources. They will be generated in target/generated-sources/xjc/generated.

Generated Classes

By default, the generated classes will be in the generated package. To customize this value, include an XJB file in the same directory as the target XSD. I prefer to do one XJB for each XSD like the following.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

    <jaxb:bindings schemaLocation="a.xsd" node="//xs:schema">
            <jaxb:package name="org.ab.a"/>

September 12th, 2017

Posted In: Javaninja

Leave a Comment

LinkedIn Auto Publish Powered By :