jaxb2-maven-plugin XJC example to Generate Java Classes from XSD

Today we will look into jaxb2-maven-plugin XJC example to generate java classes from XSD. JAXB is the middleware technology between Java Classes and XML. We can use JAXB to generate XML from Java Object and vice versa.


We use XSD to define the contract data structure, so it’s not common to generate java classes that represent the XML schema.

jaxb2-maven-plugin XJC is JAXB Binding compiler tool that can be used to generate Java Classes from XSD files.

Here we will learn how to use jaxb2-maven-plugin XJC in a maven project to generate java classes from XSD.

First of all we have to create a maven project, then we need to use jaxb2-maven-plugin plugin to generate java classes from XSD.


Notice the global.xjb file in arguments, this is where we specify java binding rules.


Here is the XSD that will be used to generate java classes.


Just build the maven project using mvn clean install and you will see java classes generated in target/generated-sources/jaxb directory.

Finally the project would look something like below image.


Further Read: JAXB Tutorial

Reference: jaxb2 maven plugin official page, java xjc

By admin

Leave a Reply

%d bloggers like this: