Java – Maven JAXB example

Generate JAXB packages based on XSD and WSDL artefacts.

Define maven plugins similar to the following example.

<build>

    <plugins>

        <plugin>

            <groupId>org.jvnet.jaxb2.maven2</groupId>

            <artifactId>maven-jaxb2-plugin</artifactId>

            <executions>

                <execution>

                    <id>xsd</id>

                    <goals>

                        <goal>generate</goal>

                    </goals>

                    <configuration>


<generateDirectory>${project.build.directory}/generated-sources/xsd</generateDirectory>

                        <extension>true</extension>

                        <schemaIncludes>

                            <include>*.xsd</include>

                        </schemaIncludes>

                    </configuration>

                </execution>

                <execution>

                    <id>wsdl</id>

                    <phase>generate-sources</phase>

                    <goals>

                        <goal>generate</goal>

                    </goals>

                    <configuration>


<generateDirectory>${project.build.directory}/generated-sources/wsdl</generateDirectory>

                        <schemaDirectory>src/main/resources/wsdl</schemaDirectory>

                        <schemaLanguage>WSDL</schemaLanguage>

                        <schemaIncludes>

                            <include>*.wsdl</include>

                        </schemaIncludes>

                        <schemaExcludes>

                            <include>*XXX*.wsdl</include>

                        </schemaExcludes>

                    </configuration>

                </execution>

            </executions>

        </plugin>

    </plugins>

</build>

me@computer /project-with-pom=xml

$ mvn generate-sources

[INFO] Scanning for projects…


[INFO] — maven-jaxb2-plugin:0.12.3:generate (wsdl) @ project —

[INFO] Up-to-date check for source resources


And if all went well the generated sources are in the specified directory.

References

https://java.net/projects/maven-jaxb2-plugin/pages/Home