Java: JAXB generation

Generating classes from XML schema:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>jaxb2-maven-plugin</artifactId>
  <version>${jaxb2.version}</version>
  <executions>
    <execution>
    <phase>none</phase>
    <id>xjc</id>
    <goals>
      <goal>xjc</goal>
    </goals>
    </execution>
  </executions>
  <configuration>
    <!-- The package of your generated sources -->
    <packageName>me.sample.package.with.xml.schema</packageName>
    <sources>
      <source>src/main/schema</source>
    </sources>
    <outputDirectory>src/main/java</outputDirectory>
    <clearOutputDir>false</clearOutputDir>
  </configuration>
</plugin>

Additionally, we need a folder with our schema in the project:

jaxb

Now, we can generate the classes from the schema types…

jaxb_maven_plugin

These classes will land in the request package declared in the plugin.

Advertisements