Reputation: 93
I'm new to Maven and AWS and I don't really understand where I'm going wrong or even where to get help here.
File:
import com.amazonaws.services.s3.AmazonS3EncryptionClientV2Builder;
Pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<groupId>com.example.myapp</groupId>
<artifactId>myapp</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>myapp</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.15.15</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.327</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I run mvn package I get:
cannot find symbol
symbol: class AmazonS3EncryptionClientV2Builder
location: package com.amazonaws.services.s3
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.878 s
[INFO] Finished at: 2021-02-04T16:38:20-08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project myapp: Compilation failure
[ERROR] /Users/LukeGarratt/myapp/src/main/java/com/example/myapp/App.java:[23,33] cannot find symbol
[ERROR] symbol: class AmazonS3EncryptionClientV2Builder
[ERROR] location: package com.amazonaws.services.s3
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I am just so confused. What am I doing? What do I need to add in pom.xml? Where? Why? How can I find that out in general? What doe this error even mean? Thanks
Upvotes: 1
Views: 2761
Reputation: 10704
You are using the older AWS Java V1 library. Its recommended to use AWS SDK for Java V2. As you are new to AWS, I recommend that you start here:
Get started with the AWS SDK for Java 2.x
Follow that topic exactly and you will get Amazon S3 Java V2 examples running. Follow these steps to complete this tutorial:
Step 1: Set up for this tutorial
Step 2: Create the project
Step 2: Step 3: Write the code
Step 4: Build and run the application
Now for your next question about Maven. Maven is an easy way to pull in the Java libs you require to compile Java projects. For more about Maven (including the role of the POM file), see this topic:
All Java AWS Service examples have a corresponding POM file in the Github repository. For example, if you want to run Amazon S3 Java V2 examples, you need to get the POM file dependencies located here:
https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/example_code/s3
Likewise, if you want to build the Amazon DynamoDB V2 examples, you need to include the POM dependencies located here:
https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/example_code/dynamodb
Every service in the Java V2 GitHub repo has a corresponding POM file with the dependencies you need to build the corresponding AWS Service examples. By adding these dependencies to your POM file, you no longer have to locate and download JAR files over the internet and manually add them to your project's Class path.
Your error is because you are using V2 POM dependencies to compile V1 code. This is V2:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.15.15</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
V2 Java packages starts with software.amazon.awssdk.services and V1 starts with com.amazonaws.services.s3. That is a quick way you can tell the difference. Mixing up V1 and V2 will always result in errors.
To learn how to code with the AWS V2 Java API, please refer to the AWS Java V2 Developer Guide here:
Developer guide - AWS SDK for Java 2.x
Upvotes: 1
Reputation: 10333
That class you are looking for com.amazonaws.services.s3.AmazonS3EncryptionClientV2Builder
is V2 Encryption for S3. Here it is
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.948</version>
</dependency>
This is an example from Aws Docs.
Upvotes: 0