Adheep
Adheep

Reputation: 1585

Getting NoSuchMethodError on HttpClients.custom().setConnectionManagerShared(true).build()

I am trying to create a HTTP connection with a URL in a EJB and the below line of code was throwing error

HttpClients.custom().setConnectionManagerShared(true).build();

ERROR:

java.lang.NoSuchMethodError: org.apache.http.impl.client.HttpClientBuilder.setConnectionManagerShared(Z)Lorg/apache/http/impl/client/HttpClientBuilder;

Initially I did not specify which version of HttpClient, so I added the GAV to my pom.xml

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

I ensured the war file had that jar. There was no error in Eclipse during compile time.

But whenever I execute it I am getting the NoSuchMethodError. I am using Java version 1.8.0_131.

I am totally confused because if I didn't get that error on compile time, why am I getting it on Runtime? Any help is greatly appreciated

Upvotes: 1

Views: 4457

Answers (1)

Santhosh Tangudu
Santhosh Tangudu

Reputation: 787

This is jar dependency problem. There are multiple jars available for this class in your code. Please check the jars which are using the package structure with below command and find out the culprit for that.

mvn dependency:tree -Dverbose -Dincludes=org.apache.http.impl.client

Upvotes: 1

Related Questions