Skip to content

JAXB2 Inheritance Plugin

Laurent Schoelens edited this page Aug 25, 2023 · 4 revisions

Usage

Activate the plugin using -Xinheritance switch.

<execution>
    <goals>
        <goal>generate</goal>
    </goals>
    <configuration>
        //...
        <bindingDirectory>
            ${basedir}/src/main/resources/....
        </bindingDirectory>
        <extension>true</extension>
        <args>
            <arg>-Xinheritance</arg>
        </args>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics</artifactId>
                <version><---Version---></version>
            </plugin>
        </plugins>
    </configuration>
</execution>

Interface implementation

In your bindings.xjb use inheritance:inherit inside jaxb:bindings to add java interface to a generated class.

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
               xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
               jaxb:extensionBindingPrefixes="xjc">

    <jaxb:bindings
            schemaLocation="mySchema.wsdl"
            node="//xs:complexType[@name='MyType']">
        <inheritance:implements>com.application.MyInterface</inheritance:implements>
    </jaxb:bindings>
</jaxb:bindings>