1

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;
mattias
  • 2,079
  • 3
  • 20
  • 27
Ajinath
  • 27
  • 3

2 Answers2

2

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

Community
  • 1
  • 1
Jaiprakash
  • 599
  • 2
  • 7
0

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

Jnn
  • 140
  • 4