Java – error running calendar API sample code
Attempt to implement from https://developers.google.com/google-apps/calendar/quickstart/java Started Google calendar code, but received the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/mortbay/jetty/Handler at CalendarQuickstart.authorize(CalendarQuickstart.java:76) at CalendarQuickstart.getCalendarService(CalendarQuickstart.java:89) at CalendarQuickstart.main(CalendarQuickstart.java:101) Caused by: java.lang.ClassNotFoundException: org.mortbay.jetty.Handler at java.net.urlclassloader$1.run(UnkNown Source) at java.net.urlclassloader$1.run(UnkNown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.urlclassloader.findClass(UnkNown Source) at java.lang.ClassLoader.loadClass(UnkNown Source) at sun.misc.Launcher$AppClassLoader.loadClass(UnkNown Source) at java.lang.ClassLoader.loadClass(UnkNown Source) ... 3 more
This line is
Credential credential = new AuthorizationCodeInstalledApp( flow,new LocalServerReceiver()).authorize("user");
Before that, I just started https://developers.google.com/google-apps/calendar/quickstart/java The code is copied and a java project is created, and the two jar files are missing
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp; import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
You get this error after importing these jar files Please help
Solution
Google Calendar API Java QuickStart works normally According to the error message you received, you seem to have missed one of the jetty dependencies If you are using the gradle Version (as shown here), please view the jar file - jetty-6.1.26.jar. Under your "gradle dependencies"
If you are missing a jetty dependency, open build. Exe Gradle and check to ensure that all dependencies listed below are included
dependencies { compile 'com.google.api-client:google-api-client:1.20.0' compile 'com.google.oauth-client:google-oauth-client-jetty:1.20.0' compile 'com.google.apis:google-api-services-calendar:v3-rev125-1.20.0' }
Finally, build and run the gradle file to download the missing dependencies You should start running now!
The above is all the contents of errors in Java - running calendar API sample code collected and sorted out by programming home for you. I hope this article can help you solve the program development problems encountered by errors in Java - running calendar API sample code.
If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.