我是Java的新手(带有maven),并试图将java的aws sdk与maven集成。我使用Visual代码是为了简单,因为它的重量轻(加上,其他IDE对我来说非常混乱)。在Mac OS Sierra上运行。
到目前为止,我已完成以下操作:
1)我已经有了maven
$mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T03:41:47+11:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"
2)创建了新的maven项目
mvn archetype:generate
-DgroupId=com.domain.javalab
-DartifactId=javalab
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false
3)在pom.xml
中添加了以下依赖项<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.271</version>
</dependency>
</dependencies>
4)创建了以下测试代码(为清晰起见,目前仅包括包和导入部分)
package com.domain.javalab;
import java.io.File;
import java.io.IOException;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.StorageClass;
... Some Code ...
5)当我尝试编译代码时,我得到&#34;包com.amazonaws不存在&#34;错误。我知道某些类路径或依赖性在某处丢失可能是愚蠢的,但我无法弄清楚在哪里。
$ javac UploadObjectSingleOperation.java
UploadObjectSingleOperation.java:6: error: package com.amazonaws does not exist
import com.amazonaws.AmazonClientException;
^
UploadObjectSingleOperation.java:7: error: package com.amazonaws does not exist
import com.amazonaws.AmazonServiceException;
^
UploadObjectSingleOperation.java:8: error: package com.amazonaws.auth.profile does not exist
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
^
UploadObjectSingleOperation.java:9: error: package com.amazonaws.services.s3 does not exist
import com.amazonaws.services.s3.AmazonS3;
.
.
运行&#39; mvn包&#39;由于上述编译错误,我认为构建失败。
我甚至尝试执行以下操作将依赖项jar复制到本地目标/依赖项文件夹。
$mvn dependency:copy-dependencies
现在我在主maven存储库(在用户主目录下的.m2 / repository /下)和本地项目目录中的目标/依赖项下都有aws-sdk jar文件。
我仍在努力找出正确的方法。在我搜索的任何地方,看起来在pom.xml中添加依赖项就可以了。或者我错过了什么,或者不按顺序?
编辑:使用版本1.11.271编辑问题。
在下面添加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>
<groupId>com.domain.javalab</groupId>
<artifactId>javalab</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>javalab</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.271</version>
</dependency>
</dependencies>
</project>