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.

jaxb2-maven-plugin

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.

pom.xml

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

global.xjb

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

Employee.xsd

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.

java-xsd-to-class

Further Read: JAXB Tutorial

Reference: jaxb2 maven plugin official page, java xjc

By admin

Leave a Reply

%d bloggers like this: