java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient

后端 未结 6 1090
粉色の甜心
粉色の甜心 2020-12-16 08:51

I am trying to make a get request from the GWT servlet to get JSON response from a web service. Following is the code in my servlet :

public String getQueDat         


        
相关标签:
6条回答
  • 2020-12-16 09:28

    What could be the possible cause of this exception?

    You may not have appropriate Jar in your class path.

    How it could be removed?

    By putting HTTPClient jar in your class path. If it's a webapp, copy Jar into WEB-INF/lib if it's standalone, make sure you have this jar in class path or explicitly set using -cp option

    as the doc says,

    Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

    The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

    Edit:
    If you are using a dependency management like Maven/Gradle (see the answer below) or SBT please use it to bring the httpclient jar for you.

    0 讨论(0)
  • 2020-12-16 09:31

    This problem occurs if there are different jar versions. Especially versions of httpcore and httpclient. Use same versions of httpcore and httpclient.

    0 讨论(0)
  • 2020-12-16 09:36

    I solved this issue for myself, I found there's was two files of http-client with different version of other dependent jar files. So there may version were collapsing between libraries files so remove all old/previous libraries files and re-add are jar files from lib folder of this zip file:

    Donwload Zip file from here

    0 讨论(0)
  • 2020-12-16 09:37

    I have solved this problem by importing the following dependency. you must manually import httpclient

    <dependency>
        <groupId>commons-httpclient</groupId>
        <artifactId>commons-httpclient</artifactId>
        <version>3.1</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
    0 讨论(0)
  • 2020-12-16 09:40

    I was facing the same issue. In my case, I had a dependency of httpclient with an older version while sendgrid required a newer version of httpclient. Just make sure that the version of httpclient is correct in your dependencies and it would work fine.

    0 讨论(0)
  • 2020-12-16 09:42

    If its a maven project, add the below dependency in your pom file

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.4</version>
        </dependency>
    
    0 讨论(0)
提交回复
热议问题