如何让maven-jaxws-plugin生成从xsd生成的类的@XmlElementWrapper?

问题描述:

我使用maven-jaxws-plugin从我的wsdl,schema中生成java类。它不会在生成的类中生成@XmlElementWrapper注释。从this后我明白我nedd使用jaxb-xew插件,但我无法得到它与maven-jaxws插件工作。任何帮助,将不胜感激。 这里是我试过如何让maven-jaxws-plugin生成从xsd生成的类的@XmlElementWrapper?

<plugin> 
    <groupId>org.jvnet.jax-ws-commons</groupId> 
    <artifactId>jaxws-maven-plugin</artifactId> 
    <version>2.2</version> 
    <executions> 
    <execution> 
     <goals> 
       <goal>wsimport</goal> 
      </goals> 
      <phase>generate-resources</phase> 
      <configuration> 
       <xjcArgs> 
        <xjcArg>-no-header</xjcArg> 
        <xjcArg>-Xxew</xjcArg> 
        <xjcArg>-Xxew:instantiate lazy</xjcArg> 
        <xjcArg>-Xxew:delete</xjcArg> 
       </xjcArgs> 
       <extension>true</extension> 

       <wsdlDirectory>${basedir}/src/main/resources</wsdlDirectory> 
       <wsdlFiles> 
        <wsdlFile>attribute-service.wsdl</wsdlFile> 
       </wsdlFiles> 
       <sourceDestDir>${project.build.directory}/generated</sourceDestDir> 
       <verbose>true</verbose> 
       <keep>true</keep> 
       <plugins> 
        <plugin> 
         <groupId>com.github.jaxb-xew-plugin</groupId> 
         <artifactId>jaxb-xew-plugin</artifactId> 
         <version>1.0</version> 
        </plugin> 
       </plugins> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

如果它只能与Maven的JAXB2-插件集成可以请你帮我把我的web服务了配置?本质上,我如何指定wsdl以及如何生成服务类? (带@WebService注解)

感谢,

Bhagya

虽然这篇文章是我写的时间为10个月大,我回答一下,以防有人会需要它。

与JAXWS-Maven的插件,以及JAXB的xew-插件的帮助,您可以生成@XmlElementWrapper标注为您的列表/对象数组

假设您的WSDL具有架构,如:

<xs:element name="books" minOccurs="0" > 
    <xs:complexType> 
    <xs:sequence> 
     <xs:element name="book" type="Book" minOccurs="0" maxOccurs="unbounded" /> 
    </xs:sequence> 
    </xs:complexType> 
</xs:element> 

它生成Java为:

@XmlElementWrapper(name = "books") 
@XmlElement(name = "book") 
protected List<Book> books; 

,这里是构建/插件

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>jaxws-maven-plugin</artifactId> 
    <version>1.12</version> 
    <configuration> 
     <wsdlDirectory>${project.basedir}/src/main/webapp/WEB-INF/wsdl/</wsdlDirectory> 
     <xjcArgs> 
      <xjcArg>-no-header</xjcArg> 
      <xjcArg>-Xxew</xjcArg> 
      <xjcArg>-Xxew:instantiate lazy</xjcArg> 
      <xjcArg>-Xxew:delete</xjcArg> 
     </xjcArgs> 
    </configuration> 
    <executions> 
     <execution> 
      <id>wsdl_import</id> 
      <goals> 
       <goal>wsimport</goal> 
      </goals> 
     </execution> 
    </executions> 

    <dependencies> 
     <dependency> 
      <groupId>com.github.jaxb-xew-plugin</groupId> 
      <artifactId>jaxb-xew-plugin</artifactId> 
      <version>1.1</version> 
     </dependency> 

     <dependency> 
      <groupId>com.sun.xml.bind</groupId> 
      <artifactId>jaxb-xjc</artifactId> 
      <version>2.2.4-1</version> 
     </dependency>     
    </dependencies> 
</plugin> 
+0

谢谢,正是我在找的东西。我不得不把xjcArgs元素放在第一个配置块中,或者参数没有被传递(maven 3.1.0)。相应地更新了答案。 – Dormouse 2014-02-14 18:35:59

sample page of the jaxb xew plugin上有可用的jaxws maven插件的配置示例。 jaxws-maven-plugin 2.3.1-b03使用jaxb-xew-plugin 1.2正常工作。