与S3连接时收到异常

时间:2015-02-19 07:17:46

标签: java amazon-web-services amazon-s3

我一直在尝试使用java连接amazon s3。我已在亚马逊控制台上注册并拥有凭据。但是,当我运行代码时连续不断地获取错误:

AmazonS3 s3client = new AmazonS3Client(credentials);

Exception received:- *Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at com.amazonaws.AmazonWebServiceClient.<clinit>(AmazonWebServiceClient.java:57)
    at bucket_conn.main(bucket_conn.java:25)*

我已经导入了所有重要的jar文件。那究竟是什么我失踪了。对于Now,只需创建连接并获取存储桶。

    String awsAccessKey = "*** access key ***";
    String awsSecretKey = "*** secret key ***";
    AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
    AmazonS3 s3client = new AmazonS3Client(credentials);
    for (Bucket bucket : s3client.listBuckets()) {
        System.out.println("Bucket Name - " + bucket.getName());
    }



 Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at com.amazonaws.util.json.Jackson.<clinit>(Jackson.java:32)
at com.amazonaws.internal.config.InternalConfig.loadfrom(InternalConfig.java:232)
at com.amazonaws.internal.config.InternalConfig.load(InternalConfig.java:249)
at com.amazonaws.internal.config.InternalConfig$Factory.<clinit>(InternalConfig.java:284)
at com.amazonaws.util.VersionInfoUtils.userAgent(VersionInfoUtils.java:139)
at com.amazonaws.util.VersionInfoUtils.initializeUserAgent(VersionInfoUtils.java:134)
at com.amazonaws.util.VersionInfoUtils.getUserAgent(VersionInfoUtils.java:95)
at com.amazonaws.ClientConfiguration.<clinit>(ClientConfiguration.java:42)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:347)
at bucket_conn.main(bucket_conn.java:25)

1 个答案:

答案 0 :(得分:3)

您在类路径中遗漏commons-logging.jar。下载并将其添加到类路径中。

更新: 现在你错过了com.fasterxml.jackson.databind.jar。下载并将其添加到类路径中。