错误:引起:java.lang.ClassNotFoundException:com.amazonaws.protocol.json.SdkJsonMarshallerFactory

时间:2017-01-04 10:46:48

标签: amazon-web-services dynamo-local

我有pom.xml文件,现在我添加了一些依赖项。我的pom文件看起来像这样......

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

现在它引起了我这样的错误......

  

引起:java.lang.ClassNotFoundException:   com.amazonaws.protocol.json.SdkJsonMarshallerFactory

2 个答案:

答案 0 :(得分:3)

实际问题是混合不同版本的AWS Jars。

例如,您应该使用1.10.391.10.3作为以下依赖项。

同样,对于所有其他 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> 

我遇到了同样的问题。为所有com.amazonaws groupId保持一致的版本可以解决问题。

答案 1 :(得分:0)

由于我无法确定您在哪里定义构建变量,我无法确定您的AWS库之间可能存在版本不匹配。该类似乎更新,并且可能不存在于您正在下拉的库中。 (我在1.11.72中看到了引用,但它可能在此之前存在)。

我会做一个&#34; mvn依赖:tree&#34;并查看各种AWS库的所有版本被拉下来并对其进行排序。

*注意:我有同样的问题,但在我的情况下,我使用MVN阴影插件,并在上游的某个地方过滤掉这些类..