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

Everything

I use this error in my project when I upgrade the aws library to the latest version 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

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

Does anyone know what I did wrong?

thanks

+9
java amazon-web-services
source share
4 answers

I had a similar problem with my grails application. In my case, a ClassNotFoundException exception was thrown from the script deployment. For me, the reason that SchemePortResolver was not resolved implicitly was because it was not needed at compile time, it was needed at runtime. Here is what I added to my BuildConfig.groovy to fix it:

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

Since the OP question was for Maven, here the equivalent includes:

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

If you add

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

it should work fine because it contains missing class definitions.

+1
source

A common cause is a Maven dependency conflict. In the example below ( pom.xml , as shown on the Eclipse Dependency Hierarchy tab), POM explicitly includes v4.1 from httpclient , which causes Maven to omit v4.5.5, which is required for aws-java-sdk-core (and thus ,, causes a similar error java.lang.NoClassDefFoundError: org / apache / http / conn / DnsResolver on com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory ...):

Screenshot of Eclipse Dependency Hierarchy

0
source

In my case, I delete the .meta file on the eclipse workstation and then import the project again, after which it works like a talisman. I could not know exactly where the problem is. Before deleting .meta, I add all the files from AWS-Java-SDK-1.11.606 \ third-party \ Lib

0
source

All Articles