maven-jaxb21-plugin的同一.xjb中的多个模式



我正在尝试使用jaxb2-commons使用inheritance选项,它适用于maven插件中指定的一个模式。但若我将另一个模式添加到同一个.xjb文件中,pom.xml会将错误显示为Unable to parse schemas exception

我怀疑这可能是因为这两个模式都有相同的targetnamespace,并试图提供不同的名称空间,这似乎有效。

因此,是否可以为两个不同的xsd保留相同的targetnamespace(在我的情况下,它只是xsd的两个不同版本,因此具有相同的targetnamespace是有意义的)。有什么想法吗?还有其他可能的解决方案吗?

编辑:我在plugin中添加了2个execution,但它在Unable to parse schemas exception中也失败了。

common.xjb

<?xml version="1.0"?>
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
    jxb:extensionBindingPrefixes="xjc">
    <!-- ================================================================ -->
    <jxb:bindings schemaLocation="product_1_0.xsd">
        <jxb:bindings node="//xs:element[@name='product']">
            <jxb:class name="ProductModel" />
        </jxb:bindings>
    </jxb:bindings>
    <jxb:bindings schemaLocation="product_1_0.xsd">
        <jxb:schemaBindings>
            <jxb:package name="org.doc.model" />
        </jxb:schemaBindings>
    </jxb:bindings>
    <jxb:bindings schemaLocation="product_1_0.xsd">
        <jxb:bindings node="//xs:element[@name='product']">
            <inheritance:extends>org.doc.model.AbstractProduct
            </inheritance:extends>
        </jxb:bindings>
    </jxb:bindings>
    <!-- ================================================================ -->
   <!-- if I add below, this fails and shows error in pom.xml  -->
    <jxb:bindings schemaLocation="product_1_1.xsd">
        <jxb:bindings node="//xs:element[@name='product']">
            <jxb:class name="ProductModel_1_1" />
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings> 

pom.xml

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb21-plugin</artifactId>
    <version>0.13.1</version>
    <executions>
        <execution>
            <id>xsdgen-JAXB</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaDirectory>src/main/resources</schemaDirectory>
                <schemaIncludes>
                    <includeSchema>*.xsd</includeSchema>
                </schemaIncludes>
                <xjbSources>common.xjb</xjbSources>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <extension>true</extension>
        <args>
            <arg>-Xsimplify</arg>
            <arg>-Xinheritance</arg>
        </args>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics</artifactId>
                <version>0.11.0</version>
            </plugin>
        </plugins>
    </configuration>
</plugin>

最后,我添加了两个不同的<execution>,并只为相应的<execution>提供了相关的模式和.xjb绑定文件,从而实现了解析。但这种方法的问题是,对于n.xsd,存在n.xjb

<executions>
    <execution>
        <id>xsdgen-JAXB</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
                <schemaIncludes>
                    <include>product_1_0.xsd</include>
                </schemaIncludes>
                <bindingIncludes>
                        <include>product_1_0.xjb</include>
                </bindingIncludes>
        </configuration>
    </execution>
     <execution>
        <id>xsdgen-JAXB-2</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
                <schemaIncludes>
                    <include>product_1_1.xsd</include>
                </schemaIncludes>
                <bindingIncludes>
                    <include>product_1_1.xjb</include>
                </bindingIncludes>
        </configuration>
    </execution>
</executions>

最新更新