J'essaie d'utiliser l'option inheritance
en utilisant jaxb2-commons
et il fonctionne très bien pour un schéma spécifié dans le plugin Maven. Mais si j'ajoute un autre schéma au même fichier .xjb, le fichier pom.xml affiche l'erreur Unable to parse schemas exception
.plusieurs schémas dans la même .xjb pour maven-plugin-jaxb21
Je soupçonne que cela puisse être parce que les deux schémas ont le même targetnamespace
et essayé de fournir un espace de noms différent et cela semble fonctionner.
Donc, est-il possible de garder le même targetnamespace pour 2 xsd différentes (dans mon cas, ce n'est que 2 versions différentes de xsd, donc il est logique d'avoir le même targetnamespace). Des idées ? toute autre solution possible?
EDIT: J'ai ajouté 2 execution
à l'intérieur du plugin
et il échoue également avec 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>