首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让maven-jaxws-plugin在从xsd生成的类上生成@XmlElementWrapper?

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

Stack Overflow用户
提问于 2013-03-06 20:06:00
回答 2查看 10K关注 0票数 5

我正在使用maven-jaxws-plugin从我的wsdl模式生成java类。它不会在生成的类中生成@XmlElementWrapper注释。从this帖子中我了解到我需要使用jaxb-xew-plugin,但无法让它与maven-jaxws-plugin一起工作。任何帮助都将不胜感激。下面是我尝试过的配置

代码语言:javascript
复制
<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-plugin集成,你能帮我把我的webservice安装好吗?本质上,我如何指定wsdl以及如何生成服务类?(使用@WebService注释)

谢谢,

巴吉亚

EN

回答 2

Stack Overflow用户

发布于 2014-01-14 22:35:09

虽然这篇文章在我写这篇文章的时候已经10个月了,但我还是回复它,以防有人需要它。

借助jaxws-maven-plugin和jaxb-xew-plugin,您可以为列表/数组对象生成@XmlElementWrapper批注

假设您的wsdl具有如下模式:

代码语言:javascript
复制
<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生成为:

代码语言:javascript
复制
@XmlElementWrapper(name = "books")
@XmlElement(name = "book")
protected List<Book> books;

下面是构建/插件

代码语言:javascript
复制
<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> 
票数 3
EN

Stack Overflow用户

发布于 2014-05-15 19:08:21

sample page of the jaxb xew plugin上提供了jaxws maven插件的配置示例。jaxws-maven-plugin 2.3.1-b03与jaxb-xew-plugin 1.2一起工作得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15246950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档