0

inheritanceオプションを使用して使用しようとしていますが、maven プラグインで指定された1 つのjaxb2-commonsスキーマで正常に動作します。しかし、同じ .xjb ファイルに別のスキーマを追加すると、pom.xml にエラーが表示されます。Unable to parse schemas exception

両方のスキーマが同じで、異なる名前空間を提供しようとしたことが原因である可能性があり、それがtargetnamespace機能していると思われます。

したがって、2 つの異なる xsd に対して同じ targetnamespace を保持することは可能ですか (私の場合、xsd の 2 つの異なるバージョンであるため、同じ targetnamespace を持つことは理にかなっています)。何か案は ?他の可能な解決策はありますか?

編集: の中に 2 を追加executionしましたが、同様pluginに失敗し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

最後に、2 つの異なるものを追加し、それぞれ<execution>に関連するスキーマと.xjbバインディング ファイルのみを提供することで解決を管理しました<execution>。しかし、このアプローチの問題は、 n に対してn .xsd存在することです。 .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 に答える