java.lang.NoClassDefFoundError: org/apache/http/message/BasicNameValuePair

huangapple go评论72阅读模式
英文:

java.lang.NoClassDefFoundError: org/apache/http/message/BasicNameValuePair

问题

public Credentials loadAuthToken(String client_id, String client_secret, String code) throws BitrixApiException {
    BitrixClientImpl bitrixClient = new BitrixClientImpl(bitrixHttpClient, credentials);
    final List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("client_id", client_id));
    params.add(new BasicNameValuePair("client_secret", client_secret));
    params.add(new BasicNameValuePair("code", code));
    String result = bitrixClient.executeOAuth(client_id, client_secret, code);

    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();
    credentials = gson.fromJson(result, AuthCredentials.class);
    return credentials;
}

Update:
pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ru.bitrix.proj</groupId>
    <artifactId>bitrix-proj</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <lombok.version>1.18.10</lombok.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.13</source>
                    <target>1.13</target>
                    <encoding>UTF8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>LATEST</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>attach-test-sources</id>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>fluent-hc</artifactId>
            <version>4.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20140107</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.8.0</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.6</version>
        </dependency>
    </dependencies>
</project>

(Note: I have removed the irrelevant parts of your code and provided a cleaned-up version for clarity.)

英文:

I make servlet java project and I need to call bitrix's rest api (Actually, it doesn't mater). I made next method:

public Credentials loadAuthToken(String client_id, String client_secret, String code) throws BitrixApiException {
BitrixClientImpl bitrixClient = new BitrixClientImpl(bitrixHttpClient, credentials);
final List&lt;NameValuePair&gt; params = new ArrayList&lt;&gt;();
params.add(new BasicNameValuePair(&quot;client_id&quot;, client_id));
params.add(new BasicNameValuePair(&quot;client_secret&quot;, client_secret));
params.add(new BasicNameValuePair(&quot;code&quot;, code));
String result = bitrixClient.executeOAuth(client_id, client_secret, code);
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
credentials = gson.fromJson(result, AuthCredentials.class);
return credentials;
}

On the first line, that's contain creating new BasicNameValuePair's object I have next error:

java.lang.NoClassDefFoundError: org/apache/http/message/BasicNameValuePair
ru.hack.project.api.bitrix.BitrixPlatform.loadAuthToken(BitrixPlatform.java:67)
ru.hack.project.platform.commands.GetCodeCommand.execute(GetCodeCommand.java:32)
ru.hack.project.platform.controllers.FrontController.doGet(FrontController.java:26)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause

What could be reason? Thanks.

Update:
pom.xml

&lt;project
xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;ru.bitrix.proj&lt;/groupId&gt;
&lt;artifactId&gt;bitrix-proj&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;properties&gt;
&lt;lombok.version&gt;1.18.10&lt;/lombok.version&gt;
&lt;/properties&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;2.5.1&lt;/version&gt;
&lt;configuration&gt;
&lt;source&gt;1.13&lt;/source&gt;
&lt;target&gt;1.13&lt;/target&gt;
&lt;encoding&gt;UTF8&lt;/encoding&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-source-plugin&lt;/artifactId&gt;
&lt;version&gt;LATEST&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;attach-sources&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;jar&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;execution&gt;
&lt;id&gt;attach-test-sources&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;test-jar&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.slf4j&lt;/groupId&gt;
&lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
&lt;version&gt;1.7.5&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.slf4j&lt;/groupId&gt;
&lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
&lt;version&gt;1.7.5&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
&lt;artifactId&gt;fluent-hc&lt;/artifactId&gt;
&lt;version&gt;4.5.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
&lt;artifactId&gt;httpclient&lt;/artifactId&gt;
&lt;version&gt;4.5.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.json&lt;/groupId&gt;
&lt;artifactId&gt;json&lt;/artifactId&gt;
&lt;version&gt;20140107&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
&lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;
&lt;version&gt;3.4&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;commons-beanutils&lt;/groupId&gt;
&lt;artifactId&gt;commons-beanutils&lt;/artifactId&gt;
&lt;version&gt;1.8.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
&lt;artifactId&gt;lombok&lt;/artifactId&gt;
&lt;version&gt;${lombok.version}&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.testng&lt;/groupId&gt;
&lt;artifactId&gt;testng&lt;/artifactId&gt;
&lt;version&gt;6.9.6&lt;/version&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;javax.servlet&lt;/groupId&gt;
&lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
&lt;version&gt;3.0.1&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
&lt;artifactId&gt;gson&lt;/artifactId&gt;
&lt;version&gt;2.8.6&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/project&gt;

I run my project by Tomcat

答案1

得分: 1

我忘记在项目设置的工件中将所有元素添加到输出布局中。

英文:

I forgot to add all elements to the output layout in the artifacts of the project settings.

huangapple
  • 本文由 发表于 2020年5月4日 05:28:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/61581865.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定