我尝试使用jaxb2-commons
使用Unable to parse schemas exception
选项,它适用于maven插件中指定的一个架构。但是,如果我将另一个架构添加到同一个.xjb文件中,则pom.xml会将错误显示为targetnamespace
。
我怀疑这可能是因为这两个架构都有相同的execution
并试图提供不同的命名空间,而且似乎有效。
因此可以为2个不同的xsd保留相同的targetnamespace(在我的情况下,它只是2个不同版本的xsd,因此有相同的targetnamespace是有意义的)。有任何想法吗 ?任何其他可能的解决方案?
编辑:我在plugin
中添加了2 Unable to parse schemas exception
,但它也失败了<?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>
。
common.xjb
<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>
的pom.xml
{{1}}
答案 0 :(得分: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>