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

三世轮回 提交于 2019-12-04 23:58:39

问题


I am using maven-jaxws-plugin to generate java classes from my wsdl, schema. It is not generating the @XmlElementWrapper annotation in the generated classes. From this post I understand I nedd to use the jaxb-xew-plugin but am unable to get it working with the maven-jaxws-plugin. Any help would be appreciated. Here is the config I tried

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

If it can only be integrated with the maven-jaxb2-plugin can you please help me get my webservice up? Essentially How do I specify the wsdl and how to generate the Service classes? (with @WebService annotation)

Thanks,

Bhagya


回答1:


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> 



回答2:


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.



来源:https://stackoverflow.com/questions/15246950/how-to-get-maven-jaxws-plugin-to-generate-xmlelementwrapper-on-classes-generate

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