6

My project is trying to upload files to Amazon S3 using aws-java-sdk-1.11.15. I'm using ant to build my project on CLI. The jackson version I'm using is 2.8.0. I'm adding my lib folder to my classpath. All my jar files are in my lib folder. I get the following on running my code -

Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectMapper.enable([Lcom/fasterx
ml/jackson/core/JsonParser$Feature;)Lcom/fasterxml/jackson/databind/ObjectMapper;
at com.amazonaws.partitions.PartitionsLoader.(PartitionsLoader.java:54)
at com.amazonaws.regions.RegionMetadataFactory.create(RegionMetadataFactory.java:30)
at com.amazonaws.regions.RegionUtils.initialize(RegionUtils.java:66)
at com.amazonaws.regions.RegionUtils.getRegionMetadata(RegionUtils.java:54)
at com.amazonaws.regions.RegionUtils.getRegion(RegionUtils.java:107)
at com.amazonaws.services.s3.AmazonS3Client.createSigner(AmazonS3Client.java:3256)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3952)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1538)
at code4goal.antony.resumeparser.ResumeParserProgram.main(ResumeParserProgram.java:613)

For this piece of code -

AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
try
{
    File file = new File(uploadFileName);
    s3client.putObject(new PutObjectRequest(bucketName, keyName, file));
}

The error is in s3client.putObject(new PutObjectRequest(bucketName, keyName, file));

srao
  • 111
  • 1
  • 9
  • Have you solved this? I have the same error with jackson 2.6.6. But I noticed that such method exists in both 2.6.6 and 2.8.2. – Jack Sep 05 '16 at 08:44
  • Yes. It was an issue with Jackson versions. – srao Sep 06 '16 at 20:43
  • Think I better identified my problem. I am running on glassfish-4.1 which comes with its own jackson library (an old one) that does not have such method. My app does not use the one I provide, but the old one that is already loaded by the application server. I didn't find a way to use s3client within glassfish-4.1 – Jack Sep 06 '16 at 21:51

4 Answers4

8

As Christophe L mentioned, that is Jackson library version conflict.

Here is a way how to easy & safely use Amazon SDK and latest Jackson in your project:

If you use other libraries that depends on Jackson conflict with version used by Amazon SDK, please consider to use aws-java-sdk-bundle It distributed together with all required libraries by renamed package names. This gives you a possibility to use v1.11.15 of Amazon Library and latest Jackson safely together.
More info: https://aws.amazon.com/blogs/developer/java-sdk-bundle/

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-bundle</artifactId>
        <version>1.11.15</version>
        <!-- <version>1.11.172</version> -->
    </dependency>

P.S. Actual for Amazon SDK 1.11.172

Yurii Bratchuk
  • 920
  • 9
  • 12
2

Seems like a library version conflict. AWS Java SDK 1.11.15 depends on Jackson version 2.6.6 (see http://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-core/1.11.15). Jackson might have some breaking changes in 2.8.0 so you may want to try to downgrade it to 2.6.6 and try again.

Christophe L
  • 13,725
  • 6
  • 33
  • 33
0

It can be caused for use external libraries, if you are also using Dagger or Butterknife you should to add guava as a dependency to your build.gradle main file like classpath :

com.google.guava:guava:20.0

In other hand, if you are having problems with larger heap for the Gradle daemon you can increase adding to your radle file:

 dexOptions {
        javaMaxHeapSize "4g"
    } 

Also remember to use annotationProcessor to compile your libraries with this kind of issues to fix the problem.

Francisco Durdin Garcia
  • 12,540
  • 9
  • 53
  • 95
0

Try to use aws-java-sdk-bundle-1.12.39 library, i solved. Try also to include com.amazonaws.thirdparty.* after using bundle.

michael
  • 146
  • 3
  • 19