最好的选择是使用jax-ws-catalog.xml
编译本地WSDL文件时,请覆盖WSDL位置并将其设置为类似
http://localhost/wsdl/SOAService.wsdl
不用担心,这只是一个URI而不是URL,这意味着您不必在该地址处使用WSDL。
您可以通过将wsdllocation选项传递给wsdl到Java编译器来实现。
这样做将从以下位置更改您的代理代码
static { URL url = null; try { URL baseUrl; baseUrl = com.ibm.eci.soaservice.SOAService.class.getResource("."); url = new URL(baseUrl, "file:/C:/local/path/to/wsdl/SOAService.wsdl"); } catch (MalformedURLException e) { logger.warning("Failed to create URL for the wsdl Location: 'file:/C:/local/path/to/wsdl/SOAService.wsdl', retrying as a local file"); logger.warning(e.getMessage()); } SOASERVICE_WSDL_LOCATION = url;}至
static { URL url = null; try { URL baseUrl; baseUrl = com.ibm.eci.soaservice.SOAService.class.getResource("."); url = new URL(baseUrl, "http://localhost/wsdl/SOAService.wsdl"); } catch (MalformedURLException e) { logger.warning("Failed to create URL for the wsdl Location: 'http://localhost/wsdl/SOAService.wsdl', retrying as a local file"); logger.warning(e.getMessage()); } SOASERVICE_WSDL_LOCATION = url;}注意,URL构造函数中的file://更改为http://。
现在出现在jax-ws-catalog.xml中。如果没有jax-ws-catalog.xml,jax-ws确实会尝试从该位置加载WSDL。
[http://localhost/wsdl/SOAService.wsdl](http://localhost/wsdl/SOAService.wsdl)
并失败,因为没有这样的WSDL将可用。
但是使用jax-ws-catalog.xml时,只要它尝试访问WSDL @,就可以将jax-ws重定向到本地打包的WSDL。
[http://localhost/wsdl/SOAService.wsdl](http://localhost/wsdl/SOAService.wsdl)
。
这是jax-ws-catalog.xml
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system"> <system systemId="http://localhost/wsdl/SOAService.wsdl" uri="wsdl/SOAService.wsdl"/> </catalog>
您正在执行的操作是告诉jax-ws,何时需要从以下位置加载WSDL:
[http://localhost/wsdl/SOAService.wsdl](http://localhost/wsdl/SOAService.wsdl)
,则应从本地路径wsdl / SOAService.wsdl加载它。
现在应该将wsdl / SOAService.wsdl和jax-ws-catalog.xml放在哪里?那是一百万美元的问题,不是吗?
它应该在您的应用程序jar的meta-INF目录中。
所以像这样
ABCD.jar | __ meta-INF | __ jax-ws-catalog.xml | __ wsdl | __ SOAService.wsdl
这样,您甚至不必覆盖客户端中访问代理的URL。WSDL是从JAR内部获取的,并且避免了在代码中必须包含硬编码的文件系统路径的情况。
有关jax-ws-catalog.xml的更多信息 http://jax-ws.java.net/nonav/2.1.2m1/docs/catalog-
support.html
希望能有所帮助



