使用jaxb2-maven-plugin实现不同的接口

时间:2018-07-31 16:02:23

标签: java jaxb code-generation xjc

我正在使用带有xjc的jaxb2-maven-plugin v.2.2从xsd文件生成对象,并且我需要一些(不是全部)生成的类来实现某些接口。 我有这个绑定文件:

<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>

但不断出现错误

  

lineNumber:5; columnNumber:78;不支持的绑定命名空间“ http://jaxb2-commons.dev.java.net/basic/inheritance”。也许您是说“ http://jaxb.dev.java.net/plugin/code-injector”?

如何实现多个接口?

1 个答案:

答案 0 :(得分:0)

以防万一:我最终使用了maven-jaxb2-plugin 与允许使用org.jvnet.jaxb2_commons:jaxb2-basics作为参数的-Xinheritance结合使用。无需更改绑定文件。

相关pom片段:

        <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>