maven-jaxb21-plugin 的同一个 .xjb 中的多个模式
multiple schemas in same .xjb for maven-jaxb21-plugin
我正在尝试通过 jaxb2-commons
使用 inheritance
选项,它适用于 Maven 插件中指定的 one 模式。但是,如果我将另一个架构添加到同一个 .xjb 文件,pom.xml 将错误显示为 Unable to parse schemas exception
.
我怀疑这可能是因为两个模式具有相同的 targetnamespace
并尝试提供不同的命名空间,这似乎有效。
那么是否可以为 2 个不同的 xsd 保留相同的目标命名空间(在我的例子中,它只是 xsd 的 2 个不同版本,所以拥有相同的目标命名空间是有意义的)。有任何想法吗 ?还有其他可能的解决方案吗?
编辑:我在 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>
并仅提供相关架构和 .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>
我正在尝试通过 jaxb2-commons
使用 inheritance
选项,它适用于 Maven 插件中指定的 one 模式。但是,如果我将另一个架构添加到同一个 .xjb 文件,pom.xml 将错误显示为 Unable to parse schemas exception
.
我怀疑这可能是因为两个模式具有相同的 targetnamespace
并尝试提供不同的命名空间,这似乎有效。
那么是否可以为 2 个不同的 xsd 保留相同的目标命名空间(在我的例子中,它只是 xsd 的 2 个不同版本,所以拥有相同的目标命名空间是有意义的)。有任何想法吗 ?还有其他可能的解决方案吗?
编辑:我在 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>
并仅提供相关架构和 .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>