如何使maven-jaxws-plugin在从xsd生成的类上生成@XmlElementWrapper? [英] how to get maven-jaxws-plugin to generate @XmlElementWrapper on classes generated from xsd?
问题描述
我正在使用maven-jaxws-plugin从我的wsdl模式生成Java类.它不会在生成的类中生成@XmlElementWrapper批注.从这篇帖子中,我了解我nedd使用jaxb-xew-plugin,但无法使其与maven-jaxws-plugin一起使用.任何帮助,将不胜感激. 这是我尝试过的配置
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>
如果它只能与maven-jaxb2-plugin集成,可以请帮助我启动我的Web服务吗?本质上,我如何指定wsdl以及如何生成Service类? (带有@WebService批注)
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)
谢谢
Bhagya
推荐答案
尽管在撰写本文时这篇文章已有10个月的历史了,但我回答是为了防止有人需要它.
although this post is 10 months old at the time of my writing, I answer it in case someone would need it.
使用jaxws-maven-plugin并借助jaxb-xew-plugin可以为列表/数组对象生成@XmlElementWrapper批注
with jaxws-maven-plugin and with the help of jaxb-xew-plugin you can generate @XmlElementWrapper annotation for your list/array objects
假设您的wsdl具有类似以下的架构:
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>
它以以下方式生成Java:
it generates java as:
@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>
这篇关于如何使maven-jaxws-plugin在从xsd生成的类上生成@XmlElementWrapper?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!