为什么我会得到;java.lang.NoClassDefFoundError:kong/unirest/unirest";?

为什么我会得到;java.lang.NoClassDefFoundError:kong/unirest/unirest";?,java,apache-httpcomponents,unirest,Java,Apache Httpcomponents,Unirest,我正在创建一个执行POST操作的Java应用程序。我需要对body执行HttpRequestWithBody以发送JSONObject。我正在使用Unirest来完成这项任务。在调试过程中,程序在创建请求并指定URL的行停止 代码如下: HttpRequestWithBody response = Unirest.post("{{URL}}"); // This line has the problem try { *** adds headers and body *** } catc

我正在创建一个执行POST操作的Java应用程序。我需要对body执行HttpRequestWithBody以发送JSONObject。我正在使用Unirest来完成这项任务。在调试过程中,程序在创建请求并指定URL的行停止

代码如下:

HttpRequestWithBody response = Unirest.post("{{URL}}"); // This line has the problem
try {
    *** adds headers and body ***
} catch (Exception ex) {
    System.out.println(ex.getMessage());
}
这是POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>{{groupId}}</groupId>
<artifactId>program</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>Program</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>10</source>
                <target>10</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>com.konghq</groupId>
        <artifactId>unirest-java</artifactId>
        <version>3.1.00</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.10</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpasyncclient</artifactId>
        <version>4.1.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.5.10</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20190722</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.5</version>
    </dependency>
</dependencies>
我尝试添加其他
apache.httpcomponents
,比如Core和Core NIO,但都没有效果


感谢您的帮助。

异常堆栈跟踪中的这一行表示您的类路径中没有类Unirest,线程“main”java.lang.NoClassDefFoundError:kong/Unirest/Unirest

然而,您似乎在依赖项部分添加了它的lib,由maven来解决,但它在“提供的范围”中,这意味着您希望其他东西为您提供它,例如ApplicationServer,但我认为这不是您的环境

因此,您是否可以删除为该依赖项提供的那一行

<dependency>
        <groupId>com.konghq</groupId>
        <artifactId>unirest-java</artifactId>
        <version>3.1.00</version>
        <scope>provided</scope>
</dependency>

com.konghq
unirest java
3.1.00
假如
然后再试一次。

删除
为我解决了这个问题

<dependency>
        <groupId>com.konghq</groupId>
        <artifactId>unirest-java</artifactId>
        <version>3.1.00</version>
        <scope>provided</scope>
</dependency>