我遇到了aws sdk和joda-time的常见问题.即使互联网上存在很多这些问题,我仍然无法解决这个问题……
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)
检查maven的依赖树我发现了几个joda依赖项. AWS似乎需要2.8.1版本,因此我在pom文件中明确添加了它,但仍然出现错误.我尝试了几个版本的joda但没有版本似乎正常工作.
谁能帮我?我只是想运行AWS sdk EC2示例…
最佳答案 在使用aws-java-sdk artifactId声明我们的AWS依赖项时,我遇到了这个问题.例如
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>x.y.z</version>
</dependency>
我们改为导入aws-java-sdk-bom依赖项,as recommended by Amazon,例如
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>x.y.z</version>
<type>pom</type>
<scope>import</scope>
</dependency>
然后单独声明我们的组件依赖关系,例如
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
这允许Maven确定aws-sdk的正确joda-time依赖关系并解决了问题.