我正在开发一个简单的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);
编译时没有错,但是当我在我的localhost上运行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中并设置了类路径。你有什么想法吗?
感谢。
答案 0 :(得分:1)
尝试将此库添加到WEB-INF / lib
http://code.google.com/p/json-simple/downloads/detail?name=json-simple-1.1.1.jar