我在使用wsgen(JAX Web服务)生成wsdl文件时遇到问题
wsgen -classpath build/classes/ -wsdl -r WebContent/WEB-INF/wsdl -s src -d build/classes/ twitterJAX.Package.ClassServices
错误:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jersey/api/cl
ient/config/ClientConfig
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.privateGetPublicMethods(Class.java:2562)
at java.lang.Class.getMethods(Class.java:1427)
at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:
358)
at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.
java:246)
at com.sun.tools.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:247)
at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:126)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.tools.ws.Invoker.invoke(Invoker.java:135)
at com.sun.tools.ws.WsGen.main(WsGen.java:57)
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.api.client.config.Cl
ientConfig
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 14 more
目前正在创建一个可以调用restfull webservice(JERSEY)的webservice(JAX) 这是我的代码:
import java.net.URI;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
@WebService
public class ClassServices {
@WebMethod
public String tweet( String pMsg,String endpoint){
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI(endpoint));
String msg=service.path("rest").path("tweet").path(pMsg).accept(
MediaType.TEXT_PLAIN).get(ClientResponse.class).toString();
return msg;
}
private static URI getBaseURI(String endpoint) {
return UriBuilder.fromUri(endpoint).build();
}
}
我已经尝试将该代码作为调用restfull服务的公共客户端,并且工作正常。 我把所有的jersey jars文件放在web-inf lib上,但是当我尝试使用wsgen工具时,总是返回错误
请帮忙...... 提前致谢