2

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>

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I will give that a try. That isn't mentioned anywhere in the dependencies. code.google.com/p/google-oauth-java-client/wiki/Setup
This project uses Maven so no manual download should be required
@KrzysztofWolny in OP's question is nothing that says that he use maven
@Jens I understood it that he's trying to run examples from github.com/google/google-api-java-client and this is a gradle/maven project. Maybe I was wrong...
@Jens suggestin manual jar manipulation in MVN project is a reason for downvoting the answer for me, yes. I'd remove this downvote but I cannot as I got error that this answer is edited.
|
2

Jens's answer is correct, you need some additional jars. Jetty is used to build a quick web server to make the OAuth process smoother for the user. It's not mandatory to use Google APIs, which is why it is not listed in the wiki, but it helps for command line applications.

To better manage your dependencies, I strongly recommend you to use maven. Since the test project you link to has a pom.xml file to describe its dependencies, it will be much easier to build the project with Maven.

If you use Eclipse, you can tell maven to build a project for eclipse by running the following command :

mvn eclipse:eclipse

You will find more info here.

Eclipse also has several plugins to integrate more easily with Maven, and IntelliJ is directly integrated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.