2017-03-03 45 views
1

我有一套從WSDL生成的Java類,我將另一個WSDL添加到我正在使用的另一個Web服務的項目中,但是從第二個WSDL生成的類中沒有@XmlRootElement註釋,並且不明白爲什麼不。想要在由jaxb2-maven-plugin生成的類中生成@XmlRootElement

這裏的聚甲醛的插件部分:

 <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>jaxb2-maven-plugin</artifactId> 
      <version>2.2</version> 
      <executions> 
       <execution> 
        <id>xjc</id> 
        <goals> 
         <goal>xjc</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <sourceType>wsdl</sourceType> 
       <sources> 
        <source>${resources.path}my-module/src/main/resources/wsdl/w1.wsdl</source> 
        <source>${resources.path}my-module/src/main/resources/wsdl/w2.wsdl</source> 
       </sources> 
       <extension>true</extension> 
       <xjbSources> 
        <xjbSource>src/main/resources/xjb/bindings.xjb</xjbSource> 
       </xjbSources> 
      </configuration> 
     </plugin> 

而這裏的bindings.xjb:

<?xml version="1.0"?> 
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" 
       xmlns:xjc= "http://java.sun.com/xml/ns/jaxb/xjc" 
       jxb:extensionBindingPrefixes="xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

節點= 「/ XS:模式」 - >

我重新廣告在this SO張貼關於使用annotate標籤,所以我插入

 <annox:annotate> 
      <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" /> 
     </annox:annotate> 

在bindings.xjb文件中指定的地方,但我當然沒有對annox前綴的定義,使沒有按沒有工作。該帖子並未指明定義的位置。

我也經歷了this SO帖子中的多個答案;不幸的是,各種方法都遺漏了一些步驟。例如,我願意直接調用marshall和unmarshall方法,但我需要知道他們所說的「JAXBContext」的位置,以及unmarshall調用的外觀或查看的位置。

annox正確的方法來做到這一點?有沒有另一種正確的方法來做到這一點?

+0

您可以發佈W1/w2.wsdl(也許在簡化形式)? –

+0

@ScottKurz會很高興,但必須等到週一(美國東部時間);只是試圖進入我的工作電腦,登錄序列有問題... – arcy

回答

0

我剛剛完成從舊的jaxb2-maven-plugin轉換到Maven的Maven-jaxb2-plugin這是18的依賴關係的依賴項。似乎有更多的文檔它。退房JAXB2 Maven Plugin Wiki

這是一個pom.xml例如:

<build> 
<plugins> 
    <plugin> 
    <groupId>org.jvnet.jaxb2.maven2</groupId> 
    <artifactId>maven-jaxb2-plugin</artifactId> 
    <version>0.13.2</version> 
    <executions> 
     <execution> 
     <id>generate</id> 
     <phase>generate-sources</phase> 
     <goals> 
      <goal>generate</goal> 
     </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <schemaDirectory>src/main/resources/</schemaDirectory> 
     <generateDirectory>${project.build.directory}/generated-sources/jaxb</generateDirectory> 
     <schemaIncludes> 
     <include>MyXSD.xsd</include> 
     </schemaIncludes> 
     <schemaExcludes> 
     <include>ObeXSD.xsd</include> 
     </schemaExcludes> 
     <args> 
     <arg>-Xannotate</arg> 
     </args> 
     <plugins> 
     <plugin> 
      <groupId>org.jvnet.jaxb2_commons</groupId> 
      <artifactId>jaxb2-basics-annotate</artifactId> 
      <version>1.0.2</version> 
     </plugin> 
     </plugins> 
    </configuration> 
    </plugin> 
    <plugin> 
     <inherited>true</inherited> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <configuration> 
      <source>1.7</source> 
      <target>1.7</target> 
     </configuration> 
    </plugin> 

下面是一個例子XSD:

<?xml version="1.0" encoding="UTF-8"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
    jaxb:version="2.1" 
    xmlns:annox="http://annox.dev.java.net" 
    jaxb:extensionBindingPrefixes="annox"> 
    <xsd:complexType name="AbstractProblemClass" abstract="true"> 
    <xsd:sequence /> 
    </xsd:complexType> 

    <xsd:complexType name="ConcreteClass"> 
    <xsd:annotation> 
     <xsd:appinfo> 
      <annox:annotate target="class">@javax.xml.bind.annotation.XmlRootElement</annox:annotate> 
     </xsd:appinfo> 
    </xsd:annotation> 
    <xsd:complexContent> 
     <xsd:extension base="AbstractProblemClass"> 
      <xsd:sequence> 
       <xsd:element name="Stuff" type="xsd:String" /> 
      </xsd:sequence> 
     </xsd:extension> 
    </xsd:complexContent> 
    </xsd:complexType> 
</xsd:schema>