1

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

4

2 回答 2

4

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

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

同样,对于所有其他com.amazonawsgroupId。

<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保持一致的版本解决了这个问题。

于 2017-01-25T13:58:32.813 回答
0

由于我看不到您在哪里定义构建变量,我无法确定,但您的 AWS 库之间可能存在版本不匹配。该类似乎较新,并且可能不存在于您要下载的任何版本的库中。(我在 1.11.72 中看到了参考,但在此之前它可能已经存在)。

我会做一个“mvn 依赖:树”,看看各种 AWS 库的所有版本都被拉下并整理出来。

*注意:我遇到了同样的问题,但在我的情况下,我使用的是 MVN 阴影插件,并且上游某处它正在过滤掉这些类..

于 2017-01-09T17:17:44.370 回答