我想开发一个显示计算机信息的程序。我发现了一个叫做"Oshi“的图书馆。当我导入这个库并运行我的代码时,有一个例外:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform
at oshi.SystemInfo.<init>(SystemInfo.java:40)
at Main.main(Main.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more我想运行以下代码:
SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
System.out.println(os);我做错什么了?
发布于 2015-12-03 08:40:49
Oshi也有一些依赖项需要下载并添加到类路径中。查看https://github.com/dblock/oshi/blob/master/pom.xml
内部检查并下载上述jars (可能从maven central )
发布于 2016-01-09 06:52:26
我是Oshi的主要开发者之一。正如@Jan所说,您需要一些依赖项。具体来说,您需要Java本地访问(JNA)和一个实现slf4j的日志系统。
如果使用管理依赖项(强烈推荐的)的build软件,单击主自述页面中的"Central Repository“链接将为您提供适当的代码,以便将其放入构建脚本中,并且如果您手动安装jars,还会告诉您需要哪些版本的jars。
发布于 2018-12-06 13:01:21
https://stackoverflow.com/questions/34061103
复制相似问题