Import library Oshi

不羁的心 提交于 2020-01-14 10:33:11

问题


I would like to develop a program that shows the computer information. I found a library called "Oshi". When I import this library and run my code, there is an exception:

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

I would like run this code:

SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
System.out.println(os);

What do I do wrong?


回答1:


Oshi has some dependencies you'll need to download and add to your classpath as well. Check out https://github.com/dblock/oshi/blob/master/pom.xml

Inside check and download the mentioned jars (from maven central maybe)




回答2:


I'm one of the main developers for Oshi. As @Jan says, you need some dependencies. Specifically you need Java Native Access (JNA) and a logging system that implements slf4j.

If you use build software that manages dependencies (highly recommended) clicking on the "Central Repository" link from the main README page will give you the appropriate code to put in your build script, and also give you an idea which versions of the jars you need if you are installing them manually.




回答3:


You must add this libs:
jna-5.1.0.jar
jna-platform-5.1.0.jar
slf4j use only slf4j-api-1.7.25.jar and slf4j-simple-1.7.25.jar



来源:https://stackoverflow.com/questions/34061103/import-library-oshi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!