0

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

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

那么是否可以为 2 个不同的 xsd 保留相同的目标命名空间(在我的情况下,它只是 2 个不同版本的 xsd,因此拥有相同的目标命名空间是有意义的)。有任何想法吗 ?任何其他可能的解决方案?

编辑:我execution在里面添加了 2plugin并且它也失败了Unable to parse schemas exception

常见的.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>
4

1 回答 1

0

最后,我通过添加两个不同<execution>的并只.xjb为各自的<execution>. 但是这种方法的问题在于,对于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>
于 2016-05-18T14:08:48.897 回答