using gson in a web service
This works well running it as a Java Application:
public class A {
public String getString(){
return "hey";
}
public String getString2(){
Gson gs = new Gson();
String a = gs.toJson("hello");
String b = gs.fromJson(a, String.class);
return b;
}
public static void main(String[] args) {
A a = new A();
System.out.println(a.getString());//returns "hey"
System.out.println(a.getString2());//returns "hello"
}
}
BUT when I publish it to tomcat and run the Client:
//client of A with AStub and ACallbackHandler au开发者_开发知识库togenerated by eclipse
public class AClient {
public static void main(String[] args) {
AStub s = new AStub();
System.out.println(s.getString().get_return());
//returns "hey"
System.out.println(s.getString2().get_return());
//fails with org.apache.axis2.AxisFault: com/google/gson/Gson
}
}
Also sometimes when respublishing the tomcat server it shows a ClassNotFoundException
I'm using Eclipse EE Indigo, Axis2, GSON 1.7.1 and tomcat 6
What am I doing wrong?
I was not adding the external jar files! Putted them in the WebContent/WEB-INF/lib of the server.
精彩评论