Несколько схем в одном и том же.xjb для maven-jaxb21-plugin
Я пытаюсь использовать inheritance
вариант использования jaxb2-commons
и он отлично работает для одной схемы, указанной в плагине maven. Но если я добавлю другую схему в тот же файл.xjb, файл pom.xml отобразит ошибку Unable to parse schemas exception
,
Я подозревал, что это может быть потому, что обе схемы имеют одинаковые targetnamespace
и попытался предоставить другое пространство имен, и это, кажется, работает.
Поэтому возможно ли сохранить одно и то же пространство имен назначения для двух разных xsd (в моем случае это всего лишь две разные версии xsd, поэтому имеет смысл иметь одно и то же пространство имен назначения). Есть идеи? любое другое возможное решение?
РЕДАКТИРОВАТЬ: я добавил 2 execution
внутри plugin
и это не с 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>
1 ответ
Наконец, мне удалось решить, добавив два разных <execution>
и предоставляя только связанную схему и .xjb
файл привязок для соответствующих <execution>
, Но проблема с этим подходом заключается в том, что для п .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>