Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS issue with joda-time (java.lang.NoSuchMethodError)

I got a common issue with the aws sdk and joda-time. And even if there are many of these issues on the internet, I am still not able to fix that...

Exception in thread "main" java.lang.NoSuchMethodError: org.joda.time.format.DateTimeFormatter.withZoneUTC()Lorg/joda/time/format/DateTimeFormatter;
at com.amazonaws.auth.internal.AWS4SignerUtils.<clinit>(AWS4SignerUtils.java:26)
at com.amazonaws.auth.internal.AWS4SignerRequestParams.<init>(AWS4SignerRequestParams.java:85)
at com.amazonaws.auth.AWS4Signer.sign(AWS4Signer.java:168)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:814)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:607)
at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:376)
at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:338)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:287)
at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.java:11132)
at com.amazonaws.services.ec2.AmazonEC2Client.runInstances(AmazonEC2Client.java:10657)
at cloudSteuerung.AmazonWebServices.create(AmazonWebServices.java:33)
at de.bla.ccu.Test.main(Test.java:16)

Checking the dependency tree of maven I noticed several joda dependencies. AWS seems to need version 2.8.1 so I added it explicitly in the pom-file but the error still occurs. I tried several versions of joda but no version seems to work properly. Can anyone help me? I am just trying to run the AWS sdk EC2 example...

dependency tree

like image 372
Brave Avatar asked Oct 19 '22 12:10

Brave


2 Answers

I experienced this issue when declaring our AWS dependency using the aws-java-sdk artifactId. e.g.

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk</artifactId>
    <version>x.y.z</version>
</dependency>

We changed to importing the aws-java-sdk-bom dependency, as recommended by Amazon, e.g.

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-bom</artifactId>
    <version>x.y.z</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

and then declaring our component dependencies individually, e.g.

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-s3</artifactId>
</dependency>

This allowed Maven to determine the correct joda-time dependency for the aws-sdk and resolved the issue.

like image 166
Malcolm Smith Avatar answered Nov 11 '22 18:11

Malcolm Smith


Obviously this means that the class-path is referring to a JAR which is of a lower version than the one that you are using (2.8.1)

I am using AWS SDK on JBOSS 6.2 EAP and had the same issue. I found that JBOSS has its own JODA under the "modules" folder which gets loaded first ignoring the JODA version I had in my lib folder. I deleted the entry of ORG.JODA in my MANIFEST.MF which means that the classloader will now look for the JODA jar from the lib. This fixed my issue.

like image 27
Sathyan AK Avatar answered Nov 11 '22 18:11

Sathyan AK