javagoogle-api-java-client

Sample Google Calendar API - Pure Java


I'm trying to setup a basic example that is documented here

I can't seem to run the application without getting one error or another.

There are no error before I run it, but when I do I get the following runtime error.

java.lang.NoClassDefFoundError: org/mortbay/jetty/Handler
    at com.azinky.CalendarSample.authorize(CalendarSample.java:95)
    at com.azinky.CalendarSample.main(CalendarSample.java:107)
Caused by: java.lang.ClassNotFoundException: org.mortbay.jetty.Handler

I then include two jar files in my classpath, jetty-6.1.26.jar and jetty-util-6.1.26.jar

Now I get another error at runtime

java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
    at com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver.getRedirectUri(LocalServerReceiver.java:98)
    at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:76)
    at com.azinky.CalendarSample.authorize(CalendarSample.java:95)
    at com.azinky.CalendarSample.main(CalendarSample.java:107)
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest

Do I need to have jetty installed on my machine in order to run this example? (The documentation doesn't say I need to)

This is my full classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
    <classpathentry kind="lib" path="libs/google-api-client-1.19.0.jar"/>
    <classpathentry kind="lib" path="libs/google-oauth-client-1.19.0.jar"/>
    <classpathentry kind="lib" path="libs/google-http-client-1.19.0.jar"/>
    <classpathentry kind="lib" path="libs/jsr305-1.3.9.jar"/>
    <classpathentry kind="lib" path="libs/google-api-services-calendar-v3-rev92-1.19.0.jar"/>
    <classpathentry kind="lib" path="libs/google-http-client-jackson2-1.19.0.jar"/>
    <classpathentry kind="lib" path="libs/google-oauth-client-jetty-1.19.0.jar"/>
    <classpathentry kind="lib" path="libs/google-oauth-client-java6-1.19.0.jar"/>
    <classpathentry kind="lib" path="libs/jackson-core-2.1.3.jar"/>
    <classpathentry kind="lib" path="libs/jetty-6.1.26.jar"/>
    <classpathentry kind="lib" path="libs/jetty-util-6.1.26.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

Solution

  • You need the org.mortbay.jetty.jar for the first class and javax.servlet.jar for the second class.

    Download it and add it to your classpath or if you use maven, look in the maven repository and add the missing dependecies to your pom.xml.