6

我正在使用 maven-jaxws-plugin 从我的 wsdl 模式生成 java 类。它不会在生成的类中生成 @XmlElementWrapper 注释。从这篇文章中,我了解到我需要使用 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 集成,你能帮我启动我的网络服务吗?本质上我如何指定 wsdl 以及如何生成服务类?(带有@WebService 注释)

谢谢,

巴迦

4

2 回答 2

3

虽然这篇文章在我写这篇文章时已有 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> 
于 2014-01-14T14:35:09.193 回答
0

jaxb xew 插件的示例页面上提供了 jaxws maven 插件的配置示例。jaxws-maven-plugin 2.3.1-b03 与 jaxb-xew-plugin 1.2 一起工作正常。

于 2014-05-15T11:08:21.017 回答