使用Maven触发wsgen&使用wsdlLocation连续wsimport [英] Use Maven to trigger a wsgen & wsimport in a row, using wsdlLocation
问题描述
我很难用maven来生成我的客户.因此,请参考直接从源代码创建Web服务客户端是我的问题的第一部分.
I have hard times using maven to generate my client. So Please refer to Creating a web-service client directly from the source for the first part of my question.
为了简单明了,我想从这里开始(src/main/java中的文件):
To keep it simple and short, I want to go from here (a file in src/main/java) :
package com.example.maven.jaxws.helloservice;
import javax.jws.WebService;
@WebService
public class Hello {
public String sayHello(String param) {
; return "Hello " + param;
}
}
到那里:
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.7-b01-
* Generated source version: 2.1
*
*/
@WebServiceClient(name = "HelloService", targetNamespace = "http://helloservice.jaxws.maven.example.com/", wsdlLocation = "http://localhost:8080/test/")
public class HelloService
extends Service
{
private final static URL HELLOSERVICE_WSDL_LOCATION;
private final static Logger logger = Logger.getLogger(com.example.wsimport.HelloService.class.getName());
...etc
仅使用1个pom.xml文件.
using only 1 pom.xml file.
请注意在最后设置的wsdlLocation. pom.xml文件可能会使用带有一些棘手配置的maven-jaxws-plugin wsgen和wsimport来实现此目的.
Please note the wsdlLocation set on the end. The pom.xml file will probably use both maven-jaxws-plugin wsgen AND wsimport with some tricky configuration to achieve this.
推荐答案
假设,您不会尝试在执行此操作的同一项目中使用生成的存根(这将创建循环依赖项,并且会一个坏主意...)然后,是的,你可以做这样的事情.
Assuming, you're not going to try to use the generated stubs in the same project that you're doing this in (which would create circular dependencies and be a bad idea...) then, yes, you can do something like this.
配置并不是那么棘手,事实上,您可能会在问题中猜到它,但是这里是这样:
The config is not all that tricky, in fact you'd kind of guessed it in your question but here goes:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-wsdl</id>
<phase>process-classes</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<sei><!-- fully qualified class name goes here --></sei>
<genWsdl>true</genWsdl>
</configuration>
</execution>
<execution>
<id>generate-stubs</id>
<phase>process-classes</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>target/jaxws/wsgen/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile><!-- class name goes here -->Service.wsdl</wsdlFile>
</wsdlFiles>
<!-- *** you need the next line to set the wsdlLocation in the generated stubs *** -->
<wsdlLocation>http://localhost:8080/test</wsdlLocation>
</configuration>
</execution>
</executions>
</plugin>
Update - to package up the generated code into a jar I would use the maven-jar-plugin like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>package-wsclient-jars</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>target/jaxws/<!-- rest of the path here, can't remember it right now --></classesDirectory>
<classifier>wsclient</classifier>
</configuration>
</execution>
</executions>
</plugin>
我已经从我们的配置中快速粘贴了此内容,但是我们的用法有所不同(因为我们压缩了wsdl文件而不是生成的客户端,但是我相信这会使您非常接近).如果您尚未使用过maven-jar-plugin,则可能必须设置该版本-2.3.1似乎是最新的.
I've quickly pasted this from our config but our usage is a little different (as we zip up the wsdl files not the generated client but I believe this will get you pretty close). You'll probably have to setup the version for the maven-jar-plugin if you're not already using it - 2.3.1 seems to be the latest.
这篇关于使用Maven触发wsgen&使用wsdlLocation连续wsimport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!