1

I am currently trying to use the AWS SDK (specifically the s3 SDK) in my project but keep getting the exception

java.lang.NoClassDefFoundError:com/amazonaws/services/s3/AmazonS3ClientBuilder

I have imported the SDK into my project using maven as shown in the SDK documentation here. The code that I am running that causes this to occur is

AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withRegion(Regions.EU_WEST_1).build();

I suspected the issue may have been occurring due to a conflict in Jackson versions between the version required by the AWS SDK and the version I was importing myself for use else where in the project although changing this does not seem to have resolved the issue. I will include my POM.xml file below.

Thanks in advance.

<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>

<groupId>com.projectname.restservice</groupId>
<artifactId>ProjectName</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ProjectName</name>

<build>
    <finalName>ProjectName</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <inherited>true</inherited>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>2.16</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-bom</artifactId>
            <version>1.11.22</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
    </dependency>

    <!--Removed due to possible conflict with AWS SDK?-->
    <!--<dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
    </dependency>-->

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.35</version>
    </dependency>

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
    </dependency>

</dependencies>

Output of: mvn dependency:tree -Dverbose -Dincludes=com.amazonaws

com.trailfinder.restservice:TrailFinderRestService:war:1.0-SNAPSHOT
[INFO] \- com.amazonaws:aws-java-sdk-s3:jar:1.11.22:compile
[INFO]    +- com.amazonaws:aws-java-sdk-kms:jar:1.11.22:compile
[INFO]    |  \- (com.amazonaws:aws-java-sdk-core:jar:1.11.22:compile - omitted for duplicate)
[INFO]    \- com.amazonaws:aws-java-sdk-core:jar:1.11.22:compile
user3075268
  • 13
  • 1
  • 6
  • @DaveMaple The output is too long for a comment I will provide a link – user3075268 Jan 25 '17 at 08:30
  • The txt file can be found [here](https://www.dropbox.com/s/g9akoy35a04mzet/mevenoutput.txt?dl=0) – user3075268 Jan 25 '17 at 08:36
  • I'm sorry, this is the one I was looking for: `mvn dependency:tree -Dverbose -Dincludes=com.amazonaws` – Dave Maple Jan 25 '17 at 12:58
  • @DaveMaple No problem, I have included the output in the original post. – user3075268 Jan 25 '17 at 13:10
  • hmm. that all looks fine -- how are you running your app when you get the error? – Dave Maple Jan 25 '17 at 13:22
  • @DaveMaple I am running the app on a local Tomcat server .Searching elsewhere there seems to be suggestions that Jersey (that my REST service app is built on) imports Jackson libraries that are also imported by AWS SDK which may cause a conflict. Jersey imports Jackson (2.3.2) and AWS SDK imports (2.6) no matter which version of Jackson I use I run into this problem. I have no idea how I can tell if it is Jackson that is causing the error. Thanks again for your help. – user3075268 Jan 25 '17 at 13:28
  • I don't think that would be related as the class that it's not finding on the classpath is `com.amazonaws.services.s3.AmazonS3ClientBuilder` which is included by the `aws-java-sdk-s3:jar`. Have you tried a good old fashioned `mvn clean && mvn package` and redeploy to tomcat? – Dave Maple Jan 25 '17 at 13:30
  • @DaveMaple Thanks for that Dave, I tried as you suggested and ran `mvn clean && mvn package` through the command line and deployed the .war file manually and that seems to have done the trick. I am developing in IntelliJ IDE so it seems like something is wrong in the project set-up within the IDE. I will update with the solution once I have figured this out. – user3075268 Jan 25 '17 at 16:29

1 Answers1

0

I think, I've found a solution / workaround to this issue. Thanks to suggestions from @DaveMaple I tried building the app through the command line and deploying the .war manually which seems to have worked.

According to this question IntelliJ IDEA uses its own build process and not Mavens. This leads me to believe that the issue was with IntelliJ's build process and nothing to do with AWS SDK or Maven. To work around this issue I configured IntelliJ to not use its own build process but instead to use Maven and then to deploy the resulting .war. Explanation on how to do this can be found here.

Community
  • 1
  • 1
user3075268
  • 13
  • 1
  • 6