2017-06-12 2 views
0

Ich habe eine Klasse zu erzeugen, die auch serializable Schnittstelle implementiert, finden Sie die XSD-Datei Ich verwende und auch Plugin Maven jaxb2Wie Java-Datei zu erzeugen, die von xsd serializable implementiert

Dies ist meine XSD-Datei

<?xml version="1.0" encoding="windows-1252" ?> 

<xsd:complexType name="Status"> 
    <xsd:sequence> 
     <xsd:element name="startTime" type="xsd:double" minOccurs="0" /> 
     <xsd:element name="endTime" type="xsd:double" minOccurs="0" /> 
    </xsd:sequence> 
</xsd:complexType> 

My JAXB2 plugin

<plugin> 
      <groupId>org.jvnet.jaxb2.maven2</groupId> 
      <artifactId>maven-jaxb2-plugin</artifactId> 
      <version>0.8.3</version> 
      <executions> 
       <execution> 
        <id>status</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
        <configuration> 
         <forceRegenerate>true</forceRegenerate> 
         <schemaDirectory>src/main/resources/xsd</schemaDirectory> 
         <schemaIncludes> 
          <include>Status.xsd</include> 
         </schemaIncludes> 
         <generatePackage>com.test.model</generatePackage> 
         <args> 
          <arg>-XtoString</arg> 
          <arg>-Xcopyable</arg> 
          <arg>-Xequals</arg> 
         </args> 
         <plugins> 
          <plugin> 
           <groupId>org.jvnet.jaxb2_commons</groupId> 
           <artifactId>jaxb2-basics</artifactId> 
           <version>0.6.4</version> 
          </plugin> 
         </plugins> 
        </configuration> 
       </execution> 

      </executions> 
      <dependencies> 
       <dependency> 
        <groupId>com.datastax.cassandra</groupId> 
        <artifactId>cassandra-driver-core</artifactId> 
        <version>3.1.3</version> 
       </dependency> 
       <dependency> 
        <groupId>com.datastax.cassandra</groupId> 
        <artifactId>cassandra-driver-mapping</artifactId> 
        <version>3.1.3</version> 
       </dependency> 
      </dependencies> 
     </plugin> 

hier erzeugten Java-Klasse Cloneable, CopyTo, Equals, ToString interfaces Umsetzung habe ich versucht, mit <arg>-Xserializable</arg> aber es hat nicht funktioniert, ich brauche diese generierten Klasse auch Serializable interface

Antwort

0

ich so benutzten jaxb2-Maven-Plugin implementieren sollten:

<plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>jaxb2-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>xjc</id> 
        <goals> 
         <goal>xjc</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <extension>true</extension> 
       <arguments>-XtoString -Xcopyable</arguments> 
       <outputDirectory>target/generated-sources/</outputDirectory> 
       <schemaDirectory>src/main/resources</schemaDirectory> 
       <bindingDirectory>src/main/resources</bindingDirectory> 
       <bindingFiles>binding.xml</bindingFiles> 
      </configuration> 
     </plugin> 

Die binding.xml:

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
jaxb:extensionBindingPrefixes="xjc" jaxb:version="1.0"> 
<jaxb:globalBindings generateIsSetMethod="true"> 
    <xjc:serializable uid="12343" /> 
</jaxb:globalBindings> 

Mit dieser Abhängigkeit:

<dependency> 
     <groupId>org.jvnet.jaxb2_commons</groupId> 
     <artifactId>jaxb2-basics</artifactId> 
</dependency> 
0

I bekam Lösung xsd:schema declaration to Modified

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
     xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
     jaxb:extensionBindingPrefixes="xjc" 
     jaxb:version="1.0"> 
<xsd:annotation> 
    <xsd:appinfo> 
    <jaxb:globalBindings generateIsSetMethod="true"> 
     <xjc:serializable uid="12343"/> 
    </jaxb:globalBindings> 
    </xsd:appinfo> 
</xsd:annotation> 

dann jaxp.properties hinzugefügt (falls sie noch nicht existiert) unter path/to/jdk1.8.0/jre/lib und dann diese Zeile in es schreiben:

javax.xml.accessExternalSchema = all 
Verwandte Themen