简体   繁体   中英

Using jaxb2-maven-plugin to implement different interfaces

I'm using jaxb2-maven-plugin v.2.2 with xjc to generate objects from xsd files, and I need some (not all) generated classes to implement some of my interfaces. I have this binding file:

<jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
          jxb:extensionBindingPrefixes="xjc"
          version="1.0">
<jxb:bindings schemaLocation="UserProfiles.xsd">
<jxb:bindings node="//xs:complexType[@name='StudentProfileGeneral']">
   <inheritance:implements>org.ande.prf.ProfileGeneral</inheritance:implements>    
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='StudentProfileDetail']">
  <inheritance:implements>org.ande.prf.ProfileDetails</inheritance:implements>
</jxb:bindings>
</jxb:bindings>

but keep getting an error

lineNumber: 5; columnNumber: 78; Unsupported binding namespace " http://jaxb2-commons.dev.java.net/basic/inheritance ". Perhaps you meant " http://jaxb.dev.java.net/plugin/code-injector "?

How can I implement several interfaces?

In case it helps anyone: I ended up using maven-jaxb2-plugin in conjunction with org.jvnet.jaxb2_commons:jaxb2-basics which allowed to use -Xinheritance as an argument. No changes were needed to binding file.

Relevant pom fragment:

        <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.14.0</version>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <extension>true</extension>
            <args>
                <arg>-Xinheritance</arg>
                <arg>-XautoNameResolution</arg>
            </args>
            <schemaDirectory>
                ${basedir}/src/main/resources/xsd
            </schemaDirectory>
            <schemaIncludes>
                <include>*.xsd</include>
            </schemaIncludes>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics</artifactId>
                    <version>1.11.1</version>
                </plugin>
            </plugins>
        </configuration>
    </plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM