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>