Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initiating AmazonS3Client on GAE throws NoClassDefFoundError

I'm trying to access an S3 bucket from Google app engine and I get an exception regarding a restricted class trying to initialize the AmazonS3Client client. See code and exception below.

Any idea how to make this work?

Code:

AmazonS3 s3 = new AmazonS3Client(new ClasspathPropertiesFileCredentialsProvider());

Exception:

Caused by: java.lang.NoClassDefFoundError: javax.management.MBeanServerFactory is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
    at com.amazonaws.jmx.MBeans.getMBeanServer(MBeans.java:111)
    at com.amazonaws.jmx.MBeans.registerMBean(MBeans.java:50)
    at com.amazonaws.jmx.SdkMBeanRegistrySupport.registerMetricAdminMBean(SdkMBeanRegistrySupport.java:27)
    at com.amazonaws.metrics.AwsSdkMetrics.registerMetricAdminMBean(AwsSdkMetrics.java:330)
    at com.amazonaws.metrics.AwsSdkMetrics.<clinit>(AwsSdkMetrics.java:308)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:188)
    at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
    at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
    at com.amazonaws.services.s3.AmazonS3Client.<clinit>(AmazonS3Client.java:231)
like image 427
AlikElzin-kilaka Avatar asked May 01 '14 08:05

AlikElzin-kilaka


1 Answers

The error you encountered means that a class used by the AWS SDK is not allowed within App Engine (for some obscure reasons).

Even if you manage to bypass this error, the AWS SDK could not be run on GAE because it uses HttpClient and not URLFetch.

For more information you could read :

  • http://www.apcjones.com/blog/2010/11/aws-sdk-for-java-modified-to-run-on-google-app-engine.html
  • Can i use org.apache.http.client.HttpClient in google app engine?
like image 104
Benoît Sauvère Avatar answered Nov 09 '22 18:11

Benoît Sauvère