Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/http/ConnectionReuseStrategy:

我只是一个虾纸丫 提交于 2019-12-01 18:57:45
asg

I realised that there are couple of dependencies with the same groupId and artifactId.

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.1-alpha1</version>
</dependency>

And

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.1</version>
</dependency>

Actually you should have only one dependency with the same groupId and artifactId.

So firstly I removed httpcore:4.1-alpha1 dependency and executed the test class. I got the exception as

java.lang.NoClassDefFoundError: org/apache/http/config/Lookup
    at com.test.so.Test1.test(Test1.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Then I used httpcore:4.1-alpha1 instead of httpcore-4.1, I got the same exception.

And hence when I updated the httpcore version to 4.3.3 based on SO link, I got the exception as -

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ssl/SSLContexts
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:966)
    at com.amitg.so.App.main(App.java:11)

Finally updating the httpcore version to 4.4, it worked perfectly fine. So it should work for all httpcore version jars above 4.4. (I tested for 4.4.4 and it also worked fine.). Version available are mentioned here. Please find the working code over here.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!