2

I am trying to use the AmazonS3ClientBuilder's defaultClient on an AWS EMR to get some files from the S3 Bucket in this way:

S3Object fullObject = null;
        try {
            String bucket = "bucket";
            String key = "key";
            AmazonS3 s3client = AmazonS3ClientBuilder.defaultClient();
            fullObject = s3client.getObject(new GetObjectRequest(bucket, key));
            
        }

. I have set a classpath in this way

EXPORT CLASSPATH=/path/to/httpclient/httpclient-4.5.2.jar:/path/to/httcore/httpcore-4.4.11.jar:

I have also put following dependencies in the classpath:

  • aws-java-sdk:1.11.820
  • aws-java-sdk-s3:1.11.820
  • aws-java-sdk-core:1.11.820
  • commons-logging: 1.2

However, every time I try to run the program i get the error:

Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
    at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.getPreferredSocketFactory(ApacheConnectionManagerFactory.java:89)
    at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:66)
    at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:59)
    at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:50)
    at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:38)
    at com.amazonaws.http.AmazonHttpClient.<init>(AmazonHttpClient.java:339)
    at com.amazonaws.http.AmazonHttpClient.<init>(AmazonHttpClient.java:323)
    at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:239)
    at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:225)
    at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:693)
    at com.amazonaws.services.s3.AmazonS3Builder$1.apply(AmazonS3Builder.java:35)
    at com.amazonaws.services.s3.AmazonS3Builder$1.apply(AmazonS3Builder.java:32)
    at com.amazonaws.services.s3.AmazonS3ClientBuilder.build(AmazonS3ClientBuilder.java:64)
    at com.amazonaws.services.s3.AmazonS3ClientBuilder.build(AmazonS3ClientBuilder.java:28)
    at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
    at com.amazonaws.services.s3.AmazonS3ClientBuilder.defaultClient(AmazonS3ClientBuilder.java:54)
    at ch.post.places.search.quags.official.run5.GetObject2.main(GetObject2.java:22)

I tried to use different versions of the dependencies, but nothing seems to work. Is there a solution to this problem?

cryptedp
  • 53
  • 1
  • 6

1 Answers1

2

Firstly, welcome to SO!

I'm pretty sure you have different versions of httpcore in your dependencies. Try printing the dependency tree and add some exclusions if there are duplicates.

Another similar post can be found here.

tpschmidt
  • 2,479
  • 2
  • 17
  • 30
  • The thing is, I provided all the dependencies in the classpath, so I though then there should be not conflicting versions. Or am I thinking wrongly= – cryptedp Jul 14 '20 at 11:41
  • did you solve it? I'm not sure on the details about providing it via the classpath so I can provide any help here – tpschmidt Jul 14 '20 at 13:36
  • 1
    Yeah there were different versions of httpcore in my classpath – cryptedp Jul 15 '20 at 13:06