[英]java.lang.NoClassDefFoundError: org/apache/http/conn/SchemePortResolver with AmazonHttpClient
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 谢谢
I had a similar issue with my grails application. 我的grails应用程序有一个类似的问题。 In my case the ClassNotFoundException was being thrown from a deploy script.
在我的情况下,ClassNotFoundException是从部署脚本抛出的。 For me the reason SchemePortResolver wasn't being resolved implicitly was because it wasn't required at compile time, it was needed at runtime.
对我来说,未隐式解析SchemePortResolver的原因是因为编译时不需要它,运行时需要它。 Here's what I added to my BuildConfig.groovy to fix it:
这是我添加到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>
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. ,它应该可以正常工作,因为它包含缺少的类定义。
A common cause would be a Maven dependency conflict. 一个常见的原因是Maven依赖冲突。 In the example below (
pom.xml
as viewed in Eclipse's Dependency Hierarchy tab), 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... ): 在下面的示例中(在Eclipse的Dependency Hierarchy选项卡中显示的
pom.xml
),POM明确包含httpclient
v4.1,这迫使Maven忽略了aws-java-sdk-core所需的v4.5.5(因此,导致类似的错误java.lang.NoClassDefFoundError:com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory ...上的org / apache / http / conn / DnsResolver ):
In my case I delete the .meta file in eclipse workplace then import the project again thereafter it work like a charm. 就我而言,我在Eclipse工作区中删除了.meta文件,然后再次导入该项目,此后它就像一个超级按钮一样工作。 Could not know where the problem exactly.
无法确切知道问题出在哪里。 Before delete .meta I add all files from aws-java-sdk-1.11.606\\third-party\\lib
在删除.meta之前,我从aws-java-sdk-1.11.606 \\ third-party \\ lib添加所有文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.