0

我正在尝试在我的企业应用程序中编写 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。任何帮助将不胜感激。

4

1 回答 1

2

如果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");
于 2013-04-08T16:39:25.237 回答