使用jaxws-maven-plugin控制JAX-WS wsdlLocation属性值(绝对路径) [英] Controlling JAX-WS wsdlLocation attribute value's (absolute path) with jaxws-maven-plugin
问题描述
我有一个JAX-WS驱动的Web服务,其WSDL我们从另一个Maven模块(我称之为 ws-consumer
)生成一个Web服务客户端。
I have a JAX-WS-driven web service whose WSDL we generate a web service client from in another Maven module (which I'll call ws-consumer
).
无论好坏,我们将已发布的WSDL(服务在发布时保存/生成的WSDL和XSD的版本)复制到我们的 src / wsdl
ws-consumer
的文件夹,然后使用 jaxws-maven-plugin
从org.jvnet使用 jaxws:wsimport
使用以下(截断的)配置生成客户端:
For better or worse, we copy the "published WSDLs" (the version of the WSDL & XSDs that the service held/generated at point of release) to our src/wsdl
folder of ws-consumer
and then use jaxws-maven-plugin
from org.jvnet to generate a client using jaxws:wsimport
with the following (truncated) configuration:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<!--phase>generate-sources</phase -->
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>src/main/resources/META-INF/wsdl/</wsdlDirectory>
<wsdlFiles>
<wsdlFile>MyWS/MyWS.wsdl</wsdlFile>
</wsdlFiles>
</configuration>
</execution>
</executions>
</plugin>
现在,生成的客户端代码在类级别应用了以下注释:
Now, the generated client code has the following annotations applied at the class level:
@WebServiceClient(name = "MyWS", targetNamespace = "http://myws/blah", wsdlLocation = "**file:/C:/some/absolute/path/src/main/resources/META-INF/wsdl/MyWS/MyWS.wsdl"**)
强调我的
正如您所希望看到的那样, wsdlLocation
属性值有一个硬编码的绝对路径,当部署服务时它将是不正确的。
As you can hopefully see, the wsdlLocation
attribute value has a hard-coded absolute path that is going to be incorrect when the service is deployed.
我有什么方法可以通过设置控制它它只是 META-INF / wsdl / MyWS / MyWS.wsdl
或其他一些值?
Is there any way I can "control" this by setting it to just META-INF/wsdl/MyWS/MyWS.wsdl
or some other value?
推荐答案
可以使用Codehaus插件:
It is possible with the Codehaus plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<keep>true</keep>
<verbose>true</verbose>
<wsdlDirectory>../wscontract/src/main/resources/wsdl</wsdlDirectory>
<wsdlLocation>wsdl/MaintainAddress.wsdl</wsdlLocation>
<sourceDestDir>src/main/java</sourceDestDir>
<bindingDirectory>.</bindingDirectory>
<bindingFiles>
<bindingFile>jaxb/xsdbindings.xml</bindingFile>
<bindingFile>jaxb/wsdlbindings.xml</bindingFile>
</bindingFiles>
</configuration>
</plugin>
也许您使用的插件有类似的选项,或者您可以考虑切换。
Perhaps the plugin you are using has a similar option or perhaps you can consider switching.
您也可以显式配置您的WSDL,在这种情况下会忽略此属性,但这可能不适合容器管理的应用程序。
You can also provision your WSDL explicitly, in which case this property is ignored, though that may not be appropriate in a container-managed application.
示例代码这里。
这篇关于使用jaxws-maven-plugin控制JAX-WS wsdlLocation属性值(绝对路径)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!