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

user1459704 picture user1459704 · Mar 6, 2013 · Viewed 9.8k times · Source

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

Answer

emil picture emil · Jan 14, 2014

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>