I am trying write JAX-WS client in my enterprise application.My client code is as follows
...
public class WSClient{
...
MyHelloService service = new MyHelloService();
service.sayHello("Test");
But I am getting following exception
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
Structure of my EAR is as below
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]
I found that the service class generated by JAX-WS has following code
package com.test;
public class MyHelloService extends Service{
..
MyHelloService(){
..
baseUrl = com.test.MyHelloService.class.getResource(".");
url = new URL(baseUrl, "MyHelloService.wsdl");
..
}
}
I also tried to change my client as follows.But its giving me same exception.
URL baseUrl = com.test.WSClient.class.getClassLoader().getResource(".");
url = new URL(baseUrl, "MyHelloService.wsdl");
MyHelloService service = new MyHelloService();
service.sayHello("Test");
I am wondering how do I load the WSDL from WEB-INF/lib/wsdl.jar. Any help would be much appreciated in this.
If the MyHelloService.wsdl
lives in wsdl.jar
, try the next:
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");