I'm trying to do a simple upload and download on Appengine with Google Cloud Storage Client Library.
During the execution, it returns these errors:
java.lang.NoClassDefFoundError: Could not initialize class com.google.appengine.tools.cloudstorage.oauth.OauthRawGcsServiceFactory
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createRawGcsService(GcsServiceFactory.java:42)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService(GcsServiceFactory.java:34)
The error points to here:
@Override
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException {
GcsFilename fileName = getFileName( request );
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, BUFFER_SIZE);
copy(Channels.newInputStream(readChannel), response.getOutputStream());
}
@Override
public void doPost( HttpServletRequest request, HttpServletResponse response ) throws IOException {
GcsOutputChannel outputChannel = gcsService.createOrReplace( getFileName(request), GcsFileOptions.getDefaultInstance() );
copy( request.getInputStream(), Channels.newOutputStream(outputChannel) );
}
How do I solve this?
One of the required jars is missing from your /war/WEB-INF/lib/
folder.
First, if you use Eclipse, check that there are no warnings in the Problems tab about a resource not being available on the server. If you see them, right-click QuickFix and choose "Copy to ..." option. If you don't use Eclipse, check manually.
If this does not help, check that you included all the dependencies necessary for you project:
https://code.google.com/p/google-api-java-client/wiki/Setup#Download_Library_with_Dependencies
One of possible causes for this problem is absence of libraries, required by the GCS library. When Google states in their docs that you need 1) Guava, 2) Joda-Time, 3) Cloud Storage API Client library - they are not joking.
The problem is, you don't need those libraries to run your application on a dev server. Your application will work fine locally. When you upload it to Google, though, you'll get a NoClassDefFoundError with an incorrect message: it will report OAuthRawGcsServiceFactory, or maybe URLFetchUtils, even though the missing classes are in Joda or in CS API.
Once you include everything required by Google, your project (hopefully) will work. Download links for those libraries can be found on the Appengine Docs page: https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/download .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With