2

我正在开发一个简单的 Servlet,用于向 Android 设备发送推送通知。这是发送消息的代码部分:

Sender sender = new Sender(API_KEY);
ArrayList<String> devicesList = new ArrayList<String>();
devicesList.add(regID1);
devicesList.add(regID2);
devicesList.add(regID3);

Message message = new Message.Builder()
.collapseKey("1")
.timeToLive(3)
.delayWhileIdle(true)
.addData("message",
        "Hello!!!")
.build();

MulticastResult result = sender.send(message, devicesList, 1);
sender.send(message, devicesList, 1);

编译时没有任何问题,但是当我在本地主机上运行 servlet 时,抛出了一个异常 - ClassNotFound 异常:

    java.lang.ClassNotFoundException: com.google.android.gcm.server.Sender
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at servlet.PostServlet.doGet(PostServlet.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

我猜这是因为 tomcat 无法加载 gcm-server.jar 中的类。但是,我已经把它放在了 WEB-INF/lib 中并设置了类路径。你有什么想法?

谢谢。

4

1 回答 1

1

尝试将此库添加到 WEB-INF/lib

http://code.google.com/p/json-simple/downloads/detail?name=json-simple-1.1.1.jar

于 2012-10-14T21:20:11.177 回答