Reputation: 125
I've got a file and get the error mentioned in the title very early:
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.PutObjectResult;
import java.io.File;
public static void main(String[] args) throws Exception {
createAndPopulateSimpleBucket();
}
public static void createAndPopulateSimpleBucket() throws Exception {
AmazonS3 s3client = new AmazonS3ClientBuilder().standard().build();
}
I get the error in the title when I call new AmazonS3ClientBuilder().
I'm new to Maven, and I think I have my pom set up correctly. Here it is:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>AWSJavaHelloWorld</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.715</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
</dependencies>
</project>
I'm guessing something is wrong with my pom, but I can't figure out what. I also get the same error when I include everything from the AWS SDK (instead of only really including the S3 dependency).
So, can anyone spot what's wrong?
Upvotes: 1
Views: 3177
Reputation: 29700
The documentation of AmazonS3ClientBuilder
states that this class does not expose a public
no-arg constructor. This means that you cannot invoke new AmazonS3ClientBuilder()
from your class.
Fortunately, this class provides two static
factory methods; one of these methods, AmazonS3ClientBuilder#defaultClient
, creates an AmazonS3
instance (the client), and the other method, AmazonS3ClientBuilder#standard
, creates an instance of the builder.
Knowing this, you can replace your code with one of the following snippets:
public static void createAndPopulateSimpleBucket() throws Exception {
AmazonS3 s3client = AmazonS3ClientBuilder.defaultClient();
}
Or:
public static void createAndPopulateSimpleBucket() throws Exception {
AmazonS3 s3client = AmazonS3ClientBuilder.standard().build();
}
Upvotes: 1