java.lang.NoClassDefFoundError: org/apache/http/conn/SchemePortResolver 与 AmazonHttpClient

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37377075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 02:26:23  来源:igfitidea点击:

java.lang.NoClassDefFoundError: org/apache/http/conn/SchemePortResolver with AmazonHttpClient

javaamazon-web-services

提问by user3277841

All

全部

I am running into this error in my project when I updated aws library to the latest 1.11.3.

当我将 aws 库更新到最新的 1.11.3 时,我在我的项目中遇到了这个错误。

Caused by:

造成的:

java.lang.NoClassDefFoundError: org/apache/http/conn/SchemePortResolver
at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.<init>(ApacheHttpClientFactory.java:40)
at com.amazonaws.http.AmazonHttpClient.<clinit>(AmazonHttpClient.java:97)
at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:145)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:393)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:373)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:355)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:339)

in my pom.xml

在我的 pom.xml

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-core</artifactId>
        <version>1.11.3</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
        <version>1.11.3</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-kms</artifactId>
        <version>1.11.3</version>
    </dependency>
    <dependency>
         <groupId>org.bouncycastle</groupId>
          <artifactId>bcprov-ext-jdk15on</artifactId>
         <version>1.54</version>
    </dependency>
    <dependency>
         <groupId>com.amazonaws</groupId>
         <artifactId>aws-encryption-sdk-java</artifactId>
          <version>0.0.1-SNAPSHOT</version>
    </dependency>

Anyone know what I did wrong?

有谁知道我做错了什么?

thanks

谢谢

回答by eidolon1138

I had a similar issue with my grails application. In my case the ClassNotFoundException was being thrown from a deploy script. For me the reason SchemePortResolver wasn't being resolved implicitly was because it wasn't required at compile time, it was needed at runtime. Here's what I added to my BuildConfig.groovy to fix it:

我的 grails 应用程序也有类似的问题。在我的情况下, ClassNotFoundException 是从部署脚本中抛出的。对我来说,SchemePortResolver 没有被隐式解析的原因是因为它在编译时不需要,在运行时需要。这是我添加到 BuildConfig.groovy 中以修复它的内容:

runtime 'org.apache.httpcomponents:httpclient:4.5.2' //Required by BeanstalkDeploy.groovy at runtime

Since the OP's question was for Maven, here's the equivalent include:

由于 OP 的问题是针对 Maven 的,因此等效的包括:

 <dependency>
   <groupId>org.apache.httpcomponents</groupId>
   <artifactId>httpclient</artifactId>
   <version>4.5.2</version>
   <scope>runtime</scope>
 </dependency>

回答by user1902945

If you add,

如果添加,

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.5.2</version>
 </dependency>

,it should work ok as it contains the missing class definitions.

,它应该可以正常工作,因为它包含缺少的类定义。

回答by PaoloC

A common cause would be a Maven dependency conflict. In the example below (pom.xmlas viewed in Eclipse's Dependency Hierarchytab), the POM explicitly includes v4.1 of httpclient, which forces Maven to omit the v4.5.5 that aws-java-sdk-core requires (and thus, causes the similar error java.lang.NoClassDefFoundError: org/apache/http/conn/DnsResolver at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory...):

一个常见的原因是 Maven 依赖冲突。在下面的示例中(pom.xml在 Eclipse 的Dependency Hierarchy选项卡中查看),POM 明确包含 v4.1 of httpclient,这强制 Maven 省略 aws-java-sdk-core 所需的 v4.5.5(因此,导致类似的错误java .lang.NoClassDefFoundError: org/apache/http/conn/DnsResolver at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory...):

Screenshot of Eclipse Dependency Hierarchy

Eclipse 依赖层次结构的屏幕截图

回答by Arun Prajapati

In my case I delete the .meta file in eclipse workplace then import the project again thereafter it work like a charm. Could not know where the problem exactly. Before delete .meta I add all files from aws-java-sdk-1.11.606\third-party\lib

在我的情况下,我删除了 eclipse 工作区中的 .meta 文件,然后再次导入该项目,它就像一个魅力。不知道问题究竟出在哪里。在删除 .meta 之前,我添加了 aws-java-sdk-1.11.606\third-party\lib 中的所有文件