I am getting this error java.lang.NoCLassDefFoundError: org/apache/http/HttpEntity when I run my application. It compiles and builds fine. But then I try to use an EJB that imports a HttpClient, I get this error.
As I have read, that I have to import the jars (httpclient-4.5 and httpcore-4.4.5) at runtime. How do I do that?
I have these jars in my gradle script. I would think that the compile would take care of pulling in all of the classes it needs to build and be good to run.
I have a implication of the HttpClient in a class. Below is a slimmed down version of the implementation:
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
public class httpClientImpl implements httpClient {
public CloseTrailerResponse closeActionFromAdapter(requestObject request) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(trailerCloseAdapterURL);
try {
..setting stuff
CloseableHttpResponse response = client.execute(httpPost);
}
}
catch(Exception ex) {
//exceptions logged
}
finally {
client.close();
}
return response;
}
}
This client is instantiated and called in the EJB.
import com.client.httpClientImpl;
private HttpClientImpl httpClientInstance = new HttpClientImpl();
private Request request;
private Response response;
//In a method the http client is called...
response = httpClientInstance.closeActionFromAdapter(request);
When I access this class at runtime, I get the class def not found.
Is the error that it needs the class at runtime or is it something else? If it needs the class at runtime, how do I add it to the classpath?
Thanks.