【问题标题】:using gson in a web service在 Web 服务中使用 gson
【发布时间】:2011-08-05 13:41:27
【问题描述】:

这很适合作为 Java 应用程序运行:

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"
    }
}

但是当我将它发布到 tomcat 并运行客户端时:

//client of A with AStub and ACallbackHandler autogenerated 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
    }
}

有时在重新发布 tomcat 服务器时,它会显示 ClassNotFoundException

我正在使用 Eclipse EE Indigo、Axis2、GSON 1.7.1 和 tomcat 6

我做错了什么?

【问题讨论】:

    标签: java web-services tomcat soap gson


    【解决方案1】:

    我没有添加外部 jar 文件! 放在服务器的WebContent/WEB-INF/lib中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-23
      • 2011-08-27
      • 1970-01-01
      • 2011-01-18
      • 2011-01-12
      相关资源
      最近更新 更多