我有一个EJB项目(在Websphere中运行),它也是一个WebService客户端。以前,我们使用wsimport命令手动创建客户端类。现在,我们希望使用JAX-WS Maven Plugin目标jaxws:wsimport自动执行流程。
除了一个事实之外,生成几乎是完美的:webservice类(带注释@WebService
)也应该有@Stateless
注释。如果没有这个,Eclipse会抱怨EJB模块中的 @WebService注释只能用于无状态会话bean 。实际上,这些类的先前版本(可能是使用手动wsimport创建的)具有@Stateless注释。
我认为它应该有一些配置告诉wsimport
将类生成为无状态。但是,我在wsimport文档和Maven插件中都没有找到它。
下面我展示了我的POM配置:
<properties>
<wsdl.dirs>${basedir}/src/main/resources/META-INF</wsdl.dirs>
<wsdl.package.basic>com.porto.sinistro.orcamentomultiempresa</wsdl.package.basic>
</properties>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<!--
Other executions, using other WSDL files.
-->
<execution>
<id>wsdl-cartaAutorizacao-exec</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>${wsdl.package.basic}.upload.cartaAutorizacao.client</packageName>
<wsdlFiles>
<wsdlFile>${wsdl.dirs}/CartaAutorizacaoWSService.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>META-INF/CartaAutorizacaoWSService.wsdl</wsdlLocation>
</configuration>
</execution>
</executions>
<configuration>
<bindingDirectory>${basedir}/src/main/java</bindingDirectory>
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
<verbose>true</verbose>
<target>2.0</target>
<xnocompile>true</xnocompile>
</configuration>
</plugin>
</plugins>
对于上面提到的WSDL,Webservice类具有以下形式:
@WebService(name = "CartaAutorizacaoWS", targetNamespace = "http://client.ws.soma.upload.sinistro.porto.com/cartaautorizacao")
// Where is the @Stateless?
public interface CartaAutorizacaoWS {
// ...
}
我应该采取哪种配置来生成@Stateless
WebServices?
谢谢,
Rafael Afonso
答案 0 :(得分:0)
我使用ANT找到了我的解决方案。
我的POM文件已更改为:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<!--
Other executions, using other WSDL files.
-->
<execution>
<id>wsdl-cartaAutorizacao-exec</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>${wsdl.package.basic}.upload.cartaAutorizacao.client</packageName>
<wsdlFiles>
<wsdlFile>${wsdl.dirs}/CartaAutorizacaoWSService.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>META-INF/CartaAutorizacaoWSService.wsdl</wsdlLocation>
</configuration>
</execution>
</executions>
<configuration>
<bindingDirectory>${basedir}/src/main/java</bindingDirectory>
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
<verbose>true</verbose>
<target>2.0</target>
<xnocompile>true</xnocompile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution> <!-- Eclipse error message. See below. -->
<id>inject-stateless</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<ant antfile="${basedir}/inject-stateless.xml" target="main" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
我的ANT脚本:
<?xml version="1.0"?>
<project default="main" basedir=".">
<property name="base.source.dir" value="./src/main/java/com/porto/sinistro/orcamentomultiempresa"/>
<target name="main" >
<antcall target="replace">
<param name="file.path" value="client/controlevagas/ControleVagasWeb.java"/>
</antcall>
<antcall target="replace">
<param name="file.path" value="client/somavistoriaweb/VistoriaWeb.java"/>
</antcall>
<!-- Other java files ... -->
</target>
<target name="replace">
<property name="java.file" location="${base.source.dir}/${file.path}"/>
<echo message="Ajustando classe ${java.file}"/>
<replace file="${java.file}">
<replacetoken><![CDATA[import javax.jws.WebMethod;]]></replacetoken>
<replacevalue><![CDATA[import javax.ejb.Stateless;
import javax.jws.WebMethod;]]></replacevalue>
</replace>
<replace file="${java.file}">
<replacetoken><![CDATA[public interface]]></replacetoken>
<replacevalue><![CDATA[@Stateless
public interface]]></replacevalue>
</replace>
</target>
</project>
虽然我的Eclipse显示错误消息插件执行未被生命周期配置覆盖:org.apache.maven.plugins:maven-antrun-plugin:1.8:run(执行:inject-stateless,阶段: generate-sources),我发现它对Maven执行没有影响。请参阅我的帖子Maven (m2e) is not executing ant task。