-1

我正在使用最新的 IntelliJ IDEA ,并且 SIGAR.jar 已使用菜单中的外部库选项添加到我的项目中。虽然从 IDE 看起来一切都很好,但当我尝试运行插件时它显示错误。打印出来的错误是:java.lang.NoClassDefFoundError: org/hyperic/sigar/SigarException

我已经尝试检查我的代码,此外我还尝试检查我的导入,并且它们应该正确完成。我还没有找到任何证据证明我的代码为什么不能工作。

这是我的 Lscpu 类,它实现了一些 SIGAR 方法。IDE 未在此代码上显示任何错误:

public class Lscpu implements CommandExecutor {
    Runtime serverRunTime = Runtime.getRuntime();

    private void getCpuTotal() {
        Sigar sigar = new Sigar();
        CpuInfo[] infos;
        try {
            infos = sigar.getCpuInfoList();
            for (int k = 0; k < infos.length; k++) {
                CpuInfo info = infos[k];
                System.out.println(Utility.ANSI_YELLOW_BACKGROUND + "--------------------------" + Utility.ANSI_RESET);
                System.out.println(Utility.ANSI_YELLOW_BACKGROUND + "[CPU Clock-Speed]: " + info.getMhz() + Utility.ANSI_RESET);
                System.out.println(Utility.ANSI_YELLOW_BACKGROUND + "[CPU Brand-Name]: " + info.getVendor() + Utility.ANSI_RESET);
                System.out.println(Utility.ANSI_YELLOW_BACKGROUND + "[CPU Model-Name]: " + info.getModel() + Utility.ANSI_RESET);
                System.out.println(Utility.ANSI_YELLOW_BACKGROUND + "[CPU Cache-Size]: " + info.getCacheSize() + Utility.ANSI_RESET);
                System.out.println(Utility.ANSI_YELLOW_BACKGROUND + "[CPU Cores-number]:" + info.getTotalCores() + Utility.ANSI_RESET);
            }
        } catch (SigarException exc) {
            exc.printStackTrace();
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            if (args.length == 0) {
                sender.sendMessage(Utility.chat("&7«« &fSystem Info &7»»"));
                getCpuTotal();
                sender.sendMessage(Utility.chat("&7 Go lookup on your console, the information have been displayed there."));
            } else {
                sender.sendMessage(Utility.chat("&4»» &7The command syntax is incorrect!"));
            }
        } else if (args.length == 0) {
            getCpuTotal();
        } else {
            System.out.println(Utility.ANSI_YELLOW_BACKGROUND + Utility.ANSI_RED + "The command syntax you used is incorrect, use /lscpu or its aliases." + Utility.ANSI_RESET);
        }
        return false;
    }
}

我希望控制台在启动时不会给出错误,当用户从控制台或游戏中插入 /lscpu 命令时,他会打印出 SIGAR 的 api 提供的 cpu 信息。这不起作用,完整的错误是这样的:

    at me.thevipershow.memoryinfo.MemoryInfo.onEnable(MemoryInfo.java:14) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]
Caused by: java.lang.ClassNotFoundException: org.hyperic.sigar.SigarException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[?:1.8.0_222]
    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:152) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:100) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_222]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_222]
    ... 12 more```
4

1 回答 1

0

您只是在 IDE 中添加了 jar,因此它不会进入您使用 Gradle 构建的 mod。您需要编辑 build.gradle 以“遮蔽”jar,或者将 jar 添加到 Minecraft 的类路径中。

于 2019-08-27T18:45:27.827 回答