2016-05-17 7 views
0

Ich versuche inheritance Option zu verwenden jaxb2-commons verwenden und es funktioniert für ein Schema fein im Maven Plugin angegeben. Wenn ich der gleichen .xjb-Datei ein weiteres Schema hinzufüge, wird in der Datei pom.xml der Fehler Unable to parse schemas exception angezeigt.mehr Schemata in gleichen .xjb für Maven-jaxb21-Plugin

Ich vermutete, dass es könnte sein, weil beide das Schema haben targetnamespace gleiche und versucht, verschiedene Namespace und das scheint zu funktionieren.

So ist es möglich, den gleichen Zielnamespace für 2 verschiedene xsd zu behalten (in meinem Fall sind es nur 2 verschiedene Versionen von xsd, so dass es sinnvoll ist, denselben Zielnamespace zu haben). Irgendwelche Ideen ? jede andere mögliche Lösung?

EDIT: Ich fügte 2 execution innerhalb der plugin und es schlägt auch mit 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> 

Antwort

0

Schließlich hatte ich Entschlossenheit geschafft, indem zwei unterschiedliche <execution> und nur das zugehörige Schema bereitstellt und .xjb Bindungsdatei für entsprechende <execution>. Aber das Problem mit diesem Ansatz ist, dass für n.xsd gibt es 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> 
Verwandte Themen