我正在尝试在我的企业应用程序中编写JAX-WS客户端。我的客户端代码如下
...
public class WSClient{
...
MyHelloService service = new MyHelloService();
service.sayHello("Test");
但我得到了以下异常
Caused By: java.io.FileNotFoundException: zip:C:/appsrv/domains/xdv_v00_7772_localhost/tmp/_WL_user/geftj9/war/WEB-INF/lib/wsClient.jar!/com/test/MyHelloService.wsdl
我的EAR结构如下
MyEAR.ear
APP-INF/wsdl.jar[contains MyHelloService.wsdl]
APP-INF/stubs.jar[contains stubs of JAX-WS]
somewar.war
WEB-INF/lib/wsdl.jar[contains WSDL]
WEB-INF/lib/stubs.jar[contains stubs of JAX-WS]
WEB-INF/lib/wsClient.jar[This jar has WS Client code using stubs]
我发现JAX-WS生成的服务类具有以下代码
package com.test;
public class MyHelloService extends Service{
..
MyHelloService(){
..
baseUrl = com.test.MyHelloService.class.getResource(".");
url = new URL(baseUrl, "MyHelloService.wsdl");
..
}
}
我也尝试按照以下方式更改我的客户端。但它给了我同样的例外。
URL baseUrl = com.test.WSClient.class.getClassLoader().getResource(".");
url = new URL(baseUrl, "MyHelloService.wsdl");
MyHelloService service = new MyHelloService();
service.sayHello("Test");
我想知道如何从WEB-INF / lib / wsdl.jar加载WSDL。 任何帮助都会在此非常感激。
答案 0 :(得分:1)
如果MyHelloService.wsdl
位于wsdl.jar
,请尝试下一个:
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
URL wsdlLocation = classloader.getResource("MyHelloService.wsdl");
QName serviceName= new QName("http://test.com/", "MyHelloService");
MyHelloService service = new MyHelloService(wsdlLocation, serviceName);
service.sayHello("Test");