Ajinath
Ajinath

Reputation: 27

Connection using client id and secrete key in java with oauth2 google api

I am new java developer.Trying to connect using client id and secret key.But still i got one exception like that.

Exception in thread "main" 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 GmailQuickstart.authorize(GmailQuickstart.java:133)
    at GmailQuickstart.main(GmailQuickstart.java:82)
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 4 more

Source Code

 GoogleClientSecrets clientSecrets =GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

        // Build flow and trigger user authorization request.
        GoogleAuthorizationCodeFlow flow =
                new GoogleAuthorizationCodeFlow.Builder(
                        HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                .setDataStoreFactory(DATA_STORE_FACTORY)
                .setAccessType("offline")
                .build();
        Credential credential = new AuthorizationCodeInstalledApp(
            flow, new LocalServerReceiver()).authorize("me");
        System.out.println(
                "Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
        return credential;

Upvotes: 1

Views: 1379

Answers (2)

Jnn
Jnn

Reputation: 140

You need to download and include the javax.servlet.jar into your java path, download

Upvotes: 0

Jaiprakash
Jaiprakash

Reputation: 609

The exception stack trace states that it was unable to find class javax.servlet.http.HttpServletRequest

Ensure that the javax servlet jar is present in the classpath.

Also, similar exception has been answered at java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest

Upvotes: 2

Related Questions