org.bukkit.plugin.InvalidPluginException:java.lang.NoClassDefFoundError - 单位

org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError - Unirest

在 spigot 插件上进行一些工作后,IntelliJ 本身并没有给出错误,但是在构建 jar 时(当加载到服务器中时)控制台打印一个 unirest 回调错误。

该项目使用 1.13.2 的 spigot 依赖项。

代码:

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.async.Callback;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.bukkit.plugin.java.JavaPlugin;

public class Weather extends JavaPlugin {

    @Override
    public void onEnable() {
        // Plugin startup logic
        getServer().getScheduler().runTaskTimer(this, () -> Unirest.get("https://data.buienradar.nl/2.0/feed/json").asJsonAsync(new Callback<JsonNode>() {
            @Override
            public void completed(HttpResponse<JsonNode> response) {
                getServer().broadcastMessage(response.getBody().toString());
                getLogger().info(response.getBody().toString());
            }

            @Override
            public void failed(UnirestException e) {
                e.printStackTrace();
            }

            @Override
            public void cancelled() {

            }
        }), 0, 20 * 30);
    }
}

org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError - Unirest 表示在运行时未找到 class Unirest。一个常见的错误是,您添加了包含 class Unirest 的库作为依赖项,但该库不会随您的插件一起导出。因此,请确保当您导出插件时,包含 class Unirest 的库也包含在生成的 jar 文件中。