2017-08-04 5 views
0

Ich versuche pojos von jaxb generiert und dafür verwende ich maven-jaxb2-plugin, ich kann Anmerkungen hinzufügen, aber nicht mit StandardwerteAnnotation nicht hinzugefügt, um Klassenebene von maven-jaxb2-plugin

ich habe unter Konfiguration für maven-jaxb2-Plugin in meinem pom.xml

<plugin> 
      <groupId>org.jvnet.jaxb2.maven2</groupId> 
      <artifactId>maven-jaxb2-plugin</artifactId> 
      <version>0.8.3</version> 
      <executions> 
       <execution> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
       </execution> 
      </executions> 

      <configuration> 
       <extension>true</extension> 
       <args> 
        <arg>-Xannotate</arg> 
       </args> 
       <generatePackage>com.abc.model</generatePackage> 
       <schemas> 
        <schema> 
         <fileset> 
          <directory>src/main/xsd</directory> 
          <includes> 
           <include>pojo.xsd</include> 
          </includes> 
         </fileset> 
        </schema> 
       </schemas> 
       <bindings> 
        <binding> 
         <fileset> 
          <directory>src/main/xsd</directory> 
          <includes> 
           <include>binding.xjb</include> 
          </includes> 
         </fileset> 
        </binding> 
       </bindings> 
       <plugins> 
        <plugin> 
         <groupId>org.jvnet.jaxb2_commons</groupId> 
         <artifactId>jaxb2-basics</artifactId> 
         <version>0.6.4</version> 
        </plugin> 
        <plugin> 
         <groupId>org.jvnet.jaxb2_commons</groupId> 
         <artifactId>jaxb2-basics-annotate</artifactId> 
         <version>0.6.4</version> 
        </plugin> 
        <plugin> 
         <groupId>com.abc.xxy</groupId> 
         <artifactId>my-custom-annotation</artifactId> 
         <version>1.1.1</version> 
        </plugin> 
        <plugin> 
         <groupId>org.jvnet.jaxb2_commons</groupId> 
         <artifactId>jaxb2-namespace-prefix</artifactId> 
         <version>1.1</version> 
        </plugin> 
       </plugins> 
      </configuration> 
     </plugin> 

und meine XSD und Bindung sieht aus wie folgt: -

XSD

<xs:element name="batch" type="Batch"/> 

<xs:complexType name="Batch"> 
    <xs:sequence> 
     <xs:element name='student' type='StudentType' minOccurs='0' 
        maxOccurs='unbounded'/> 
    </xs:sequence> 
</xs:complexType> 

<xs:complexType name="StudentType"> 
    <xs:sequence> 
     <xs:element name="firstname" type="xs:string"/> 
     <xs:element name="lastname" type="xs:string"/> 
     <xs:element name="nickname" type="xs:string"/> 
     <xs:element name="marks" type="xs:positiveInteger"/> 
    </xs:sequence> 
    <xs:attribute name='rollno' type='xs:positiveInteger'/> 
</xs:complexType> 

Bindung
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<jaxb:bindings xmlns:jaxb="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:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:annox="http://annox.dev.java.net" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" 
     jaxb:extensionBindingPrefixes="xjc annox" 
     version="2.1"> 

    <jaxb:bindings schemaLocation="pojo.xsd" node="/xs:schema"> 
     <jaxb:bindings node="xs:complexType[@name='Batch']"> 
      <annox:annotate target="class"> 
       <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation"/> 
       <!--<annox:annotate target="class">com.abc.xyx.MyCustomAnnotation</annox:annotate>--> 
      </annox:annotate> 
     </jaxb:bindings> 
     <jaxb:bindings node="xs:complexType[@name='StudentType']/xs:sequence/xs:element[@name='firstname']"> 
      <annox:annotate target="field"> 
       <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation"/> 
      </annox:annotate> 
     </jaxb:bindings> 
     <jaxb:bindings node="xs:complexType[@name='StudentType']/xs:sequence/xs:element[@name='lastname']"> 
      <!--<annox:annotate target="field">@com.abc.xyx.MyCustomAnnotation(propertyAlias = "cemaforr:timestamp")</annox:annotate>--> 
      <annox:annotate target="field"> 
       <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation"/> 
      </annox:annotate> 
     </jaxb:bindings> 
    </jaxb:bindings> 

</jaxb:bindings> 

Kann jemand bitte, wo ich zu verkennen, danke im voraus

Antwort

0

gelöst mein Problem vorschlagen, durch Änderung binding.xml machen, Das Problem war, dass ich Feldwerte nicht an Annotation übergeben konnte.

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
    <jaxb:bindings 
      xmlns:jaxb="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:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:annox="http://annox.dev.java.net" 
      xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" 
      jaxb:extensionBindingPrefixes="xjc annox" 
      version="2.1"> 

     <jaxb:bindings schemaLocation="pojo.xsd" node="/xs:schema"> 
      <jaxb:bindings node="xs:complexType[@name='Batch']"> 
       <annox:annotate target="class"> 
        <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation"/> 
       </annox:annotate> 
      </jaxb:bindings> 
      <jaxb:bindings node="xs:complexType[@name='StudentType']/xs:sequence/xs:element[@name='firstname']"> 
       <annox:annotate target="field"> 
        <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation"> 
         <annox:annotate annox:field="propertyNane">Property Value 1</annox:annotate> 
        </annox:annotate> 
       </annox:annotate> 
      </jaxb:bindings> 
      <jaxb:bindings node="xs:complexType[@name='StudentType']/xs:sequence/xs:element[@name='lastname']"> 
      <annox:annotate target="field"> 
       <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation"> 
        <annox:annotate annox:field="propertyNane">Property Value 2</annox:annotate> 
       </annox:annotate> 
      </annox:annotate> 
      </jaxb:bindings> 
     </jaxb:bindings> 

    </jaxb:bindings> 
Verwandte Themen