我有一个JAX-WS驱动的Web服务,其WSDL我们从另一个Maven模块(我称之为ws-consumer
)生成一个Web服务客户端。
无论好坏,我们将“已发布的WSDL”(服务在发布时保存/生成的WSDL和XSD的版本)复制到src/wsdl
ws-consumer
的{{1}}文件夹中。然后使用org.jvnet中的jaxws-maven-plugin
使用jaxws:wsimport
生成具有以下(截断)配置的客户端:
<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>
现在,生成的客户端代码在类级别应用了以下注释:
@WebServiceClient(name = "MyWS", targetNamespace = "http://myws/blah", wsdlLocation = "**file:/C:/some/absolute/path/src/main/resources/META-INF/wsdl/MyWS/MyWS.wsdl"**)
强调我的
正如您所希望看到的那样,wsdlLocation
属性值具有硬编码的绝对路径,在部署服务时该路径将不正确。
有什么方法可以通过将其设置为META-INF/wsdl/MyWS/MyWS.wsdl
或其他值来“控制”这个?
答案 0 :(得分:13)
可以使用Codehaus插件:
<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>
也许您使用的插件有类似的选项,或者您可以考虑切换。
您也可以显式配置WSDL,在这种情况下会忽略此属性,但这在容器管理的应用程序中可能不合适。
示例代码here。
答案 1 :(得分:7)
将wsdlLocation与org.jvnet.jax-ws-commons中的jaxws-maven-plugin一起使用:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>arsdev.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>wsdl/*</wsdlLocation>
<!-- Keep generated files -->
<keep>true</keep>
<packageName>jaxws.remedy.client.generated</packageName>
<!-- generated source files destination -->
<sourceDestDir>target/generated-code/src</sourceDestDir>
</configuration>
</plugin>
答案 2 :(得分:0)
我投了@dean-schulze的答案,因为它适用于 org.jvnet.jax-ws-commons:jaxws-maven-plugin 插件。
使用CLI在本地显示帮助也可能很有意思,如下所示:
mvn jaxws:help -Dgoal=wsimport -Ddetail
如上一个答案所述,我们可以使用 wsdlLocation 参数,如下所述:
wsdlLocation
@WebService.wsdlLocation and @WebServiceClient.wsdlLocation value.
Can end with asterisk in which case relative path of the WSDL will be
appended to the given wsdlLocation.
Example:
...
<configuration>
<wsdlDirectory>src/mywsdls</wsdlDirectory>
<wsdlFiles>
<wsdlFile>a.wsdl</wsdlFile>
<wsdlFile>b/b.wsdl</wsdlFile>
<wsdlFile>${basedir}/src/mywsdls/c.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>http://example.com/mywebservices/*</wsdlLocation>
</configuration>
...
wsdlLocation for a.wsdl will be http://example.com/mywebservices/a.wsdl
wsdlLocation for b/b.wsdl will be
http://example.com/mywebservices/b/b.wsdl
wsdlLocation for ${basedir}/src/mywsdls/c.wsdl will be
file://absolute/path/to/c.wsdl
Note: External binding files cannot be used if asterisk notation is in
place.
-wsdllocation 选项也记录在JDK的 wsimport 命令中:
但它只是说(见@WebServiceClient javadoc):
Specifies the @WebServiceClient.wsdlLocation value.
答案 3 :(得分:-1)
版本1.12无法识别<wsdlLocation>
。它抱怨道:
No WSDLs are found to process, Specify atleast one of the following parameters: wsdlFiles, wsdlDirectory or wsdlUrls.
版本1.9(在您的示例中)只是忽略所有内容而不生成任何代码。
某些事情必须改变。