how to get maven-jaxws-plugin to generate @XmlElementWrapper on classes generated from xsd?

心已入冬 提交于 2019-12-03 16:29:04
emil

although this post is 10 months old at the time of my writing, I answer it in case someone would need it.

with jaxws-maven-plugin and with the help of jaxb-xew-plugin you can generate @XmlElementWrapper annotation for your list/array objects

assuming your wsdl has schema like:

<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>

it generates java as:

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

and here is the build/plugin

<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> 

There are configuration examples for the jaxws maven plugin available on the sample page of the jaxb xew plugin. jaxws-maven-plugin 2.3.1-b03 work fine with jaxb-xew-plugin 1.2.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!