Generating JAXB classes with Maven plugin

How to generate JAXB classes based on XSD file automatically using Maven?

First make sure that you compile your application using at least Java SE 6:





Then goto this website:


If you want to generate JAXB classes based on XSD, you internally use xjc command in JDK. Add this plugin to pom.xml:


Change package name to whatever you like. Add your XSD file inside src/main/xsd and once you call at least mvn generate-sources, JAXB classes will be generated automatically inside target/generated-sources/jaxb. Btw. Maven phase generate-sources is called very early in Maven lifecycle (before compile).