Can't access Google Drive libraries in GAE in Java in Eclipse -- classpath or war problem?

117 views
Skip to first unread message

Bob Flavin

unread,
Aug 16, 2013, 3:49:36 PM8/16/13
to google-a...@googlegroups.com

I get NoClassDefFoundError when trying to use a class like com/google/api/client/googleapis/auth/oauth2/GoogleClientSecrets.  I'm trying to use the Java  Google Drive library in my GAE servlet.    I tested the code in a standalone java app and with works.  The java code compiles without complaint in Eclipse  But when I try to run the servlet in the 'localhost' server in Eclipse, I get the NoClassDefFoundError.  GoogleClientSecrets (just a convenient, arbitrary class to test on) is in com.google.api.client.googleapis.auth.oauth2 in C:\app\gDrive\libs\google-api-client-1.16.0-rc.jar on my system.  It appears in the 'Referenced Libraries for the project.  Its in the Java Build Path as an external jar, (The jar is 'check' marked in the Order and Export tab of Eclipse Java Build Path dialog -- I think that means include this jar in the WAR file for the server.

The fact that Eclipse doesn't see an error when I refer to GoogleClientSecrets means to me that the Build Path has the class in it.  There must be something I don't understand about the class loader environment for the 'localhost' 'server', or for the class loader for the servlet -- that is not finding the google-api-client-1.16.0-rc.jar.  (The server starts fine, but when the servlet loads (when the first HTTP request is handled) I get the NoClassDefFoundError.

Are there any restrictions about classes or jars that GAE loads?  Is there something different about the way the server/servlet class loader works?

Vinny P

unread,
Aug 17, 2013, 12:51:00 AM8/17/13
to google-a...@googlegroups.com
On Fri, Aug 16, 2013 at 2:49 PM, Bob Flavin <ribo...@gmail.com> wrote:
I get the NoClassDefFoundError.  GoogleClientSecrets (just a convenient, arbitrary class to test on) is in com.google.api.client.googleapis.auth.oauth2 in C:\app\gDrive\libs\google-api-client-1.16.0-rc.jar on my system.  It appears in the 'Referenced Libraries for the project.  Its in the Java Build Path as an external jar, (The jar is 'check' marked in the Order and Export tab of Eclipse Java Build Path dialog -- I think that means include this jar in the WAR file for the server.

 
 
 Try the following:
 
1. Remove the API Client JAR from your application.
2. Copy the API client JAR from your hard drive to the /WAR/WEB-INF/lib/ directory within your Eclipse project.
3. When the prompt comes up, choose the option to copy the library, not to link to it.
4. After the JAR is copied over, right click it and select Add To Build Path
 
Rebuild your project and run it in the dev appserver.
 
 
-----------------
-Vinny P
Technology & Media Advisor
Chicago, IL

App Engine Code Samples: http://www.learntogoogleit.com
 

Bob Flavin

unread,
Sep 5, 2013, 12:52:01 PM9/5/13
to google-a...@googlegroups.com
----------------------------- Resolved
After lots of searching, I found that I was using the wrong jar, that's why it couldn't be found.  Vinny P is right that the jars should be in <project>/war/WEB-INF/lib directory. Notably that the normal eclipse class loading mechanism (using 'Build Path') is not what is used by the development app server (or the production server) to find classes -- that is what is used to load the app server, not what the app server uses to load 'isolated' apps.)  This page: http://stackoverflow.com/questions/18281420/why-do-i-get-a-noclassdeffounderror-trying-to-use-google-drive-in-gae-in-java-in  describes what I learned about the loading process why which the app server finds app classes.

Vinny P

unread,
Sep 5, 2013, 3:37:59 PM9/5/13
to google-a...@googlegroups.com
On Thu, Sep 5, 2013 at 11:52 AM, Bob Flavin <ribo...@gmail.com> wrote:
After lots of searching, I found that I was using the wrong jar, that's why it couldn't be found.  Vinny P is right that the jars should be in <project>/war/WEB-INF/lib directory.


Good to hear that it's working for you.


On Thu, Sep 5, 2013 at 11:52 AM, Bob Flavin <ribo...@gmail.com> wrote:
Notably that the normal eclipse class loading mechanism (using 'Build Path') is not what is used by the development app server (or the production server) to find classes -- that is what is used to load the app server, not what the app server uses to load 'isolated' apps.)  This page: http://stackoverflow.com/questions/18281420/why-do-i-get-a-noclassdeffounderror-trying-to-use-google-drive-in-gae-in-java-in  describes what I learned about the loading process why which the app server finds app classes.


As an addendum, it might be better to move to Maven or another management tool if your project is using a lot of libraries.
Reply all
Reply to author
Forward
0 new messages