How to generate Java classes from XSD using jaxb-2 Maven?
Andrew Henderson
Updated on March 21, 2026
How to generate Java classes from XSD using jaxb-2 Maven?
The JAXB-2 Maven plugin uses the JDK-supplied tool XJC, a JAXB Binding compiler tool that generates Java classes from XSD (XML Schema Definition). Let’s create a simple user.xsd file and use the JAXB-2 Maven plugin to generate Java classes from this XSD schema: Let’s configure the JAXB-2 Maven plugin:
What is JAXB class generator in XML?
The XML parser parses the XML schema and sends the parsed data to the JAXB class generator. The class generator creates Java classes and interfaces based on the input XML schema. By default, one XML element or type declaration generates one interface and one class.
How does the jaxb-2 Maven plugin work with XJC?
The JAXB-2 Maven plugin uses the JDK-supplied tool XJC, a JAXB Binding compiler tool that generates Java classes from XSD (XML Schema Definition). Let’s create a simple user.xsd file and use the JAXB-2 Maven plugin to generate Java classes from this XSD schema:
How do I use the JAXB API?
You can use the JAXB API and tools to perform the following basic tasks: Generate and compile JAXB classes from an XML schema with the orajaxb command-line utility. To use the JAXB class generator to generate Java classes you must provide it with an XML schema. DTDs are not supported by JAXB.
How do I convert a JAXB to XML?
Marshalling – Converting Java Object to XML Marshalling provides a client application the ability to convert a JAXB derived Java object tree into XML data. By default, the Marshaller uses UTF-8 encoding when generating XML data. Next, we will generate XML files from Java objects.
Does JAXB work with XML schema language?
In addition, pre-release versions of the JAXB Reference Implementation worked only with DTDs — that is, not with schemas written in the XML Schema Language. However, the XML Schema Language is much richer than DTDs.
What is JAXB and how to use it?
There is no need to create and use a parser and no need to write a content handler with callback methods. What this means is that developers can access and process XML data without having to know XML or XML processing. JAXB simplifies access to an XML document from a Java program by presenting the XML document to the program in a Java format.