我在调用Google日历时遇到问题 使用Google Web Toolkit在服务器端(servlet)上的API。我下载了java的库,我添加了外部JAR eclipse以下文件:gdata-core,gdata-calendar,gdata- calendar-meta,gdata-client-meta,gdata-client。 然后,我创建了一个方法,如下所示:
import com.google.gdata.client.calendar.CalendarService;
import com.google.gdata.data.calendar.CalendarEntry;
import com.google.gdata.data.calendar.CalendarFeed;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class GCalServImpl extends RemoteServiceServlet implements
GCalServ {
@Override
public String RetrieveCalendars() {
// TODO Auto-generated method stub
// Create a CalenderService and authenticate
try{
CalendarService myService = new CalendarService("taskR");
myService.setUserCredentials(***username***, "***password***");
// Send the request and print the response
URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/
allcalendars/full");
CalendarFeed resultFeed = myService.getFeed(feedUrl,
CalendarFeed.class);
System.out.println("Your calendars:");
System.out.println();
String s = "";
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
CalendarEntry entry = resultFeed.getEntries().get(i);
s=entry.getTitle().getPlainText();
System.out.println("\t" + s);
return s;
}
}catch(Exception e){
e.printStackTrace();
}
return null;
}
然后我从客户端调用它进行基本的异步调用。如果 我尝试启动程序时遇到以下错误:
WARNING: Error for /taskr/cal
java.lang.NoClassDefFoundError: com/google/gdata/client/calendar/
CalendarService
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at
org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:
428)
at
org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:
339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
487)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1166)
at
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:
51)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:
122)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
418)
at
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:
70)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:349)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.ClassNotFoundException:
com.google.gdata.client.calendar.CalendarService
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
at
com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:
151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
... 33 more
我该怎么办?
编辑:我使用谷歌网络工具包及其标准的RPC模式。
答案 0 :(得分:2)
您已经在Eclipse中添加了jar文件,但看起来您还没有配置Jetty来查找它们 - 这就是您获得NoClassDefFoundError
的原因。