简体   繁体   English

构建AWS SDK Jar以导入单个包

[英]Build AWS SDK Jar to Import for a Single Package

I would like to use the Java AWS SDK only for S3 at the moment. 我想目前仅将Java AWS SDK用于S3。 So, instead of importing the entire AWS SDK jar file I wanted to only import the necessary packages for accessing my S3 bucket into my web application (IDE: Netbeans). 因此,我不想导入整个AWS SDK jar文件,而是只导入用于访问我的S3存储桶的必要软件包到我的Web应用程序(IDE:Netbeans)。

To do this, I read that I should use Maven to build the jar I need. 为此,我读到我应该使用Maven来构建我需要的jar。

I have tried two approaches but can't seem to also include all of the aws-java-sdk-s3 dependencies in the jar that I am building. 我尝试了两种方法,但似乎也不包括我正在构建的jar中的所有aws-java-sdk-s3依赖项。

First approach 第一种方法

1) I download the zipped aws-sdk-java folder from https://github.com/aws/aws-sdk-java 1)我从https://github.com/aws/aws-sdk-java下载压缩的aws-sdk-java文件夹

2) I unzip to a local folder. 2)我解压缩到本地文件夹。

3) I navigate to the aws-java-sdk-s3 (ie: where the pom is located) folder in my console, then type "mvn clean install". 3)我导航到我的控制台中的aws-java-sdk-s3(即:pom所在的位置)文件夹,然后键入“mvn clean install”。

While this builds a jar file (located in aws-java-sdk-s3/target ), the jar does not contain the dependencies specified in the POM file (eg: it does not include the BasicAWSCredentials class in the core package which I need). 虽然这构建了一个jar文件(位于aws-java-sdk-s3/target ),但jar不包含POM文件中指定的依赖项(例如:它不包含我需要的核心包中的BasicAWSCredentials类) 。

Second Approach Change the POM file located in the aws-java-sdk-master folder so that it imports the BOM and specifying my requirement (S3) by adding: 第二种方法更改位于aws-java-sdk-master文件夹中的POM文件,以便通过添加以下内容导入BOM并指定我的要求(S3):

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.amazonaws</groupId>
      <artifactId>aws-java-sdk-bom</artifactId>
      <version>1.10.67</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
<dependencies>
  <dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-s3</artifactId>
  </dependency>
</dependencies>

and removing all other dependencies listed in the POM (eg: junit). 并删除POM中列出的所有其他依赖项(例如:junit)。

This approach fails while building the DynamoDB package, which I don't even need it to be building (I want to specify that it only needs S3). 这种方法在构建DynamoDB软件包时失败,我甚至不需要构建它(我想指定它只需要S3)。

Any suggestions as to what I'm doing wrong? 关于我做错了什么的任何建议? Perhaps the main issue here is that I'm new to Maven. 也许这里的主要问题是我是Maven的新手。

Thank you 谢谢

You can download the Jar that you are interested directly from maven : http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-s3/1.10.66/aws-java-sdk-s3-1.10.66.jar 您可以直接从maven下载您感兴趣的Jar: http//central.maven.org/maven2/com/amazonaws/aws-java-sdk-s3/1.10.66/aws-java-sdk-s3-1.10 .66.jar

update the URL with the version of the sdk you want to use and you can just import the jar in your project, no need to rebuild it 使用您要使用的sdk版本更新URL,您只需在项目中导入jar,无需重建它

update your pom.xml properly likewise, 同样更新你的pom.xml,

<dependencies>

....


<!-- AWS dependencies -->

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

....

</dependencies>

It worked fine for me using Gradle. 使用Gradle对我来说很好。 Here is the Gradle build file I used as advised by the API doc . 这是我在API doc中建议使用的Gradle构建文件。

group 'aws.test'
version '1.0'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
  mavenCentral()
}

buildscript {
  repositories {
      mavenCentral()
  }
  dependencies {
      classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
  }
}

apply plugin: "io.spring.dependency-management"

dependencyManagement {
  imports {
      mavenBom 'software.amazon.awssdk:bom:2.0.0-preview-12'
  }
}

dependencies {
  compile 'software.amazon.awssdk:s3'
  testCompile group: 'junit', name: 'junit', version: '4.11'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM