gpt4 book ai didi

java - SIGAR api 抛出 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-12-02 01:11:58 31 4
gpt4 key购买 nike

我正在使用最新的 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```

最佳答案

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

关于java - SIGAR api 抛出 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57680308/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com