Getting below error while trying to create s3 bucket of aws using java api :
Error : Exception in thread "main" java.lang.NoClassDefFoundError: software/amazon/awssdk/protocols/query/internal/unmarshall/AwsXmlErrorUnmarshaller at software.amazon.awssdk.protocols.xml.internal.unmarshall.AwsXmlErrorTransformer.(AwsXmlErrorTransformer.java:40) at software.amazon.awssdk.protocols.xml.internal.unmarshall.AwsXmlErrorTransformer.(AwsXmlErrorTransformer.java:34) at software.amazon.awssdk.protocols.xml.internal.unmarshall.AwsXmlErrorTransformer$Builder.build(AwsXmlErrorTransformer.java:113) at software.amazon.awssdk.protocols.xml.AwsXmlProtocolFactory.createErrorTransformer(AwsXmlProtocolFactory.java:135) at software.amazon.awssdk.protocols.xml.AwsS3ProtocolFactory.createErrorCouldBeInBodyResponseHandler(AwsS3ProtocolFactory.java:80) at software.amazon.awssdk.services.s3.DefaultS3Client.createBucket(DefaultS3Client.java:1144) at com.act.niti.main(niti.java:33) Caused by: java.lang.ClassNotFoundException: software.amazon.awssdk.protocols.query.internal.unmarshall.AwsXmlErrorUnmarshaller at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ... 8 more
Code :
try {
Region region = Region.US_EAST_2;
S3Client s3 = S3Client.builder()
.region(region)
.build();
S3Waiter s3Waiter = s3.waiter();
CreateBucketRequest bucketRequest = CreateBucketRequest.builder()
.bucket("abc")
.build();
s3.createBucket(bucketRequest); //creating s3 bucket
System.out.println("bucket........abc");
HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder()
.bucket("abc")
.build();
// Wait until the bucket is created and print out the response
WaiterResponse<HeadBucketResponse> waiterResponse =
s3Waiter.waitUntilBucketExists(bucketRequestWait);
waiterResponse.matched().response().ifPresent(System.out::println);
System.out.println("abc" " is ready");
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
Note : Using java 8
CodePudding user response:
Just tested this AWS SDK for Java V2 example and it works fine -- as shown in this screen shot that shows debugging line by line.
Your error looks like missing classes. Did you use the POM dependencies shown in the POM file here?
https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/s3