Error : Caused by: java.lang.ClassNotFoundException: com.amazonaws.protocol.json.SdkJsonMarshallerFactory

5k views Asked by At

I have pom.xml file and now i have added some dependency. My pom file looks like this...

<!-- Libraries -->
 <dependencies> 
    <dependency>
       <groupId>com.amazonaws</groupId>
       <artifactId>aws-java-sdk</artifactId>
       <version>1.10.39</version>
     </dependency> 
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-core</artifactId>
        <version>1.10.3</version>
    </dependency>   
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-cbor -->
    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-cbor</artifactId>
        <version>2.7.0</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-dynamodb</artifactId>
        <version>${aws.java.sdk.version}</version>
    </dependency>

        <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
         <version>1.10.3</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>DynamoDBLocal</artifactId>
        <version>${aws.java.sdk.version}</version>
    </dependency>
    <dependency>
        <groupId>com.thinkaurelius.titan</groupId>
        <artifactId>titan-core</artifactId>
        <version>${titan.version}</version>
    </dependency>
<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
    <groupId>joda-time</groupId>
         <artifactId>joda-time</artifactId>
         <version>2.8.1</version>
</dependency>
    <dependency>
        <groupId>com.thinkaurelius.titan</groupId>
        <artifactId>titan-test</artifactId>
        <version>${titan.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
    <dependency>
        <groupId>com.thinkaurelius.titan</groupId>
        <artifactId>titan-es</artifactId>
        <version>${titan.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.codahale.metrics</groupId>
        <artifactId>metrics-core</artifactId>
        <version>${metrics3.version}</version>
    </dependency>
    <dependency>
        <groupId>au.com.bytecode</groupId>
        <artifactId>opencsv</artifactId>
        <version>${opencsv.version}</version>
    </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>${httpcomponents.httpclient.version}</version>
</dependency>
   <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-json-org</artifactId>
        <version>${jackson2.version}</version>
    </dependency> 
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
     <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <!-- Gremlin -->
    <dependency>
        <groupId>org.apache.tinkerpop</groupId>
        <artifactId>gremlin-core</artifactId>
        <version>${tinkerpop.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tinkerpop</groupId>
        <artifactId>gremlin-groovy</artifactId>
        <version>${tinkerpop.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tinkerpop</groupId>
        <artifactId>gremlin-test</artifactId>
        <version>${tinkerpop.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- for Gremlin console -->
    <dependency>
        <groupId>org.apache.tinkerpop</groupId>
        <artifactId>gremlin-console</artifactId>
        <version>${tinkerpop.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler.plugin.version}</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven.surefire.version}</version>
            <!-- Use the single-integration-tests and multi-integration-tests profiles below -->
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>${maven.resources.plugin.version}</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>${dependency.plugin.version}</version>
            <executions>
    <execution>
                    <id>copy-dependencies</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution> 
            </executions> 
        </plugin>
    </plugins>
</build>
<profiles>
    <profile>
        <id>start-dynamodb-local</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>${exec.maven.plugin.version}</version>
                    <executions>
                        <execution>
                            <phase>initialize</phase>
                            <configuration>
                                <executable>java</executable>
                                <arguments>
                                    <argument>-cp</argument>
                                    <classpath/>
                                    <argument>-Dsqlite4java.library.path=${basedir}/target/dependencies</argument>
                                    <argument>com.amazonaws.services.dynamodbv2.local.main.ServerRunner</argument>
                                   <!-- <argument>-inMemory</argument> -->
                                    <argument>-port</argument>
                <argument>${dynamodb-local.port}</argument>
                <argument>-dbPath</argument>

            <argument>${basedir}/com/amazon/titan/diskstorage/dynamodb/DynamoDBStoreManager</argument>                  
        <!--    <argument>${basedir}/src/test/resources/com/amazon/titan/diskstorage/dynamodb/DynamoDBStoreManager</argument> -->
                                    <argument>-sharedDb</argument>
                                </arguments>
                            </configuration>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>single-integration-tests</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven.surefire.version}</version>
                    <executions>
                        <execution>
                            <id>surefire-it</id>
                            <phase>test</phase>
                            <goals>
                                <goal>test</goal>
                            </goals>
                            <configuration>
                                <excludedGroups>${test.excluded.groups},com.amazon.titan.testcategory.MultipleItemTests</excludedGroups>
                                <groups>com.amazon.titan.testcategory.SingleItemTests</groups>
                                <skip>false</skip>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>multi-integration-tests</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven.surefire.version}</version>
                    <executions>
                        <execution>
                            <id>surefire-it</id>
                            <phase>test</phase>
                            <goals>
                                <goal>test</goal>
                            </goals>
                            <configuration>
                                <excludedGroups>${test.excluded.groups},com.amazon.titan.testcategory.SingleItemTests</excludedGroups>
                                <groups>com.amazon.titan.testcategory.MultipleItemTests</groups>
                                <skip>false</skip>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>start-gremlin</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>${exec.maven.plugin.version}</version>
                    <executions>
                        <execution>
                            <phase>test</phase>
                            <configuration>
                                <executable>java</executable>
                                <arguments>
                                    <argument>-Dsqlite4java.library.path=${basedir}/target/dependencies</argument>
                                    <argument>-cp</argument>
                                    <argument>${basedir}/target/dependencies/*${path.separator}${basedir}/target/dynamodb-titan100-storage-backend-1.0.0.jar</argument>
                                    <argument>org.apache.tinkerpop.gremlin.console.Console</argument>
                                </arguments>
                            </configuration>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
<repositories>
    <repository>
        <id>dynamodblocal</id>
        <name>AWS DynamoDB Local Release Repository</name>
        <url>http://localhost:4567</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <version>${hamcrest.version}</version>
        </dependency>
        <dependency>
            <groupId>com.almworks.sqlite4java</groupId>
            <artifactId>sqlite4java</artifactId>
            <version>${sqlite4java.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>${commons.logging.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

Now it caused me an error something like this...

Caused by: java.lang.ClassNotFoundException: com.amazonaws.protocol.json.SdkJsonMarshallerFactory

2

There are 2 answers

0
Nate Anderson On

Since I can't see where you're defining your build variables I can't be sure but you probably have a version mismatch between your AWS libs. That class seems to be newer and might not exist in whichever version of the libs you are pulling down. (I'm seeing reference in 1.11.72 but it may have existed before that).

I would do a "mvn dependency:tree" and see what all versions of the various AWS libs are being pulled down and sort them out.

*Note: I'm having this same issue but in my case I'm using the MVN shade plugin and somewhere upstream it's filtering out these classes..

0
notionquest On

The actual problem is mixing the different version of the AWS Jars.

For example, you should either use 1.10.39 or 1.10.3 for the below dependencies.

Similarly, for all other com.amazonaws groupIds.

<dependency>
       <groupId>com.amazonaws</groupId>
       <artifactId>aws-java-sdk</artifactId>
       <version>1.10.39</version>
     </dependency> 
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-core</artifactId>
        <version>1.10.3</version>
    </dependency> 

I have come across the same problem. Keeping the same version consistently for all com.amazonaws groupId resolved the problem.