【问题标题】:how to get maven-jaxws-plugin to generate @XmlElementWrapper on classes generated from xsd?如何让 maven-jaxws-plugin 在从 xsd 生成的类上生成 @XmlElementWrapper?
【发布时间】:2013-03-06 12:06:00
【问题描述】:

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

<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 集成,你能帮我启动我的 web 服务吗?本质上我如何指定 wsdl 以及如何生成服务类? (带有@WebService 注解)

谢谢,

佛法

【问题讨论】:

    标签: wsimport maven-jaxb2-plugin jax-ws-customization jaxb-xew-plugin


    【解决方案1】:

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

    使用 jaxws-maven-plugin 和 jaxb-xew-plugin,您可以为列表/数组对象生成 @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> 
    

    【讨论】:

    • 谢谢,正是我想要的。我不得不将 xjcArgs 元素放在第一个配置块中,否则参数没有通过(maven 3.1.0)。相应地更新了答案。
    【解决方案2】:

    sample page of the jaxb xew plugin 上提供了 jaxws maven 插件的配置示例。 jaxws-maven-plugin 2.3.1-b03 与 jaxb-xew-plugin 1.2 配合良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      • 2013-12-18
      • 2013-08-30
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      • 2011-08-24
      相关资源
      最近更新 更多