Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethodError with jackson while trying to upload files to Amazon S3 using java.

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));

like image 654
srao Avatar asked Jul 14 '16 17:07

srao


1 Answers

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

like image 188
Yurii Bratchuk Avatar answered Sep 30 '22 14:09

Yurii Bratchuk