ben*_*ben 13 maven-2 jax-ws maven-plugin
我很难使用maven来生成我的客户端.因此,请参阅我的问题的第一部分直接从源代码创建Web服务客户端.
为了简单和简短,我想从这里(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;
}
}
Run Code Online (Sandbox Code Playgroud)
到那里:
/**
* 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
Run Code Online (Sandbox Code Playgroud)
仅使用1个pom.xml文件.
请注意最后设置的wsdlLocation.pom.xml文件可能会使用maven-jaxws-plugin wsgen和wsimport以及一些棘手的配置来实现这一点.
mac*_*tch 17
假设,你不会尝试在你正在做的同一个项目中使用生成的存根(这将创建循环依赖并且是一个坏主意......)然后,是的,你可以做这样的事情.
配置并不是那么棘手,实际上你在你的问题中猜到了它,但是这里有:
<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>
Run Code Online (Sandbox Code Playgroud)
更新 - 将生成的代码打包到jar中我会像这样使用maven-jar-plugin:
<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>
Run Code Online (Sandbox Code Playgroud)
我很快就从配置中粘贴了这个,但我们的用法有点不同(因为我们压缩了wsdl文件而不是生成的客户端,但我相信这会让你非常接近).如果你还没有使用它,你可能需要设置maven-jar-plugin的版本 - 2.3.1似乎是最新版本.
我已经在相同的过程中成功了。目的是为我们的应用程序中的Web服务创建Web服务代理JAR。
我们的应用程序中有三个Web服务(当前)。它们是由Maven项目创建的,该项目使用服务和支持类构建WAR,该类包含sun-jaxws.xml描述符以及web.xml。
Web服务Maven项目是多项目构建的一部分,因此Web服务WAR是EAR中的一个模块,还具有EJB JAR,用户界面WAR和其他JAR(以及相关性)。
理想情况下,我会创建依赖于Web服务WAR项目,并使用Maven的JAX-WS插件的目标另一个Maven项目的客户端代理JAR wsgen,然后wsimport做的工作。
但是我无法使Maven项目将WAR用作依赖对象,因此无法将其类(在中WEB-INF/classes)添加到类路径中。我尝试了AppFuse Warpath插件,但无法解压缩WAR依赖关系。
最后,我不得不诉诸于在一个Maven项目中构建和安装多个工件。我对调查结果wsgen和wsimport与第二产物:
jaxws-maven-pluginwsgen如果目标不在当前项目中,则它们需要自己的目标依赖项,否则无法找到它们。(即使verbose设置了true此目标,也很少发出有用的信息。)wsgen目标必须要求每个服务生成WSDL。wsimport因为所有服务共享许多支持类,所以一次在所有WSDL上一次调用该目标。(由于所有生成的类都放在一个客户端代理程序包中,因此,即使源于不同的程序包,类名在原始来源中也不应重叠,这一点很重要。)maven-jar-plugin:jar并被maven-install-plugin:install-file打包和安装客户端代理JAR。以下是POM的关键部分,并提供了一些评论:
<parent>
<groupId>lighthouse.navigate</groupId>
<artifactId>navigate</artifactId>
<version>3.9.0-SNAPSHOT</version>
</parent>
<artifactId>navigate-webservice</artifactId>
<packaging>war</packaging>
<name>Navigate WebService</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>navigate-util</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<!-- snip -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<!-- WSDLs must be generated for each service. -->
<execution>
<id>generate-client-wsdl</id>
<phase>process-classes</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<sei>nav.ws.client.ClientWebService</sei>
<genWsdl>true</genWsdl>
</configuration>
</execution>
<execution>
<id>generate-licence-wsdl</id>
<phase>process-classes</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<sei>nav.ws.licence.LicenceWebService</sei>
<genWsdl>true</genWsdl>
</configuration>
</execution>
<!-- snip -->
<!-- Single generation of client proxy because WSDLs share classes. -->
<execution>
<id>generate-proxies</id>
<phase>process-classes</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>target/generated-sources/wsdl</wsdlDirectory>
<destDir>target/wsgen/classes</destDir>
<packageName>nav.ws.proxy</packageName>
<xnocompile>false</xnocompile>
</configuration>
</execution>
</executions>
<!--
NB: wsgen needs its own dependencies declared so it can find
classes outside this project.
-->
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>navigate-util</artifactId>
<version>${project.version}</version>
</dependency>
<!-- snip -->
</dependencies>
</plugin>
<!-- Package client proxy JAR as secondary artifact. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>package-wsclient</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>target/wsgen/classes</classesDirectory>
<finalName>navigate-wsclient-${project.version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
<!-- Install client proxy JAR as secondary artifact. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>install-wsclient</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>target/navigate-wsclient-${project.version}.jar</file>
<groupId>${project.groupId}</groupId>
<artifactId>navigate-wsclient</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)