错误信息
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/platform/mac/SystemB$Timevalat java.lang.ClassLoader.defineClass1(Native Method)at java.lang.ClassLoader.defineClass(ClassLoader.java:757)at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)at java.net.URLClassLoader.access$100(URLClassLoader.java:74)at java.net.URLClassLoader$1.run(URLClassLoader.java:369)at java.net.URLClassLoader$1.run(URLClassLoader.java:363)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:362)at java.lang.ClassLoader.loadClass(ClassLoader.java:419)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)at java.lang.ClassLoader.loadClass(ClassLoader.java:352)at oshi.SystemInfo.createOperatingSystem(SystemInfo.java:87)at oshi.util.Memoizer$1.get(Memoizer.java:61)at oshi.SystemInfo.getOperatingSystem(SystemInfo.java:76)at test.SystemHardwareInfo.main(SystemHardwareInfo.java:13)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.platform.mac.SystemB$Timevalat java.net.URLClassLoader.findClass(URLClassLoader.java:382)at java.lang.ClassLoader.loadClass(ClassLoader.java:419)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)at java.lang.ClassLoader.loadClass(ClassLoader.java:352)... 16 more
原因
在引用 oshi-core 依赖时发生的错误
<dependency> <groupId>com.github.oshi</groupId> <artifactId>oshi-core</artifactId> <version>6.4.0</version>
</dependency>
解决方案
<dependency> <groupId>com.github.oshi</groupId> <artifactId>oshi-core</artifactId> <version>6.4.0</version> <!-- 将jna 和 jna-platform排除--><exclusions> <exclusion> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> </exclusion> <exclusion> <groupId>net.java.dev.jna</groupId> <artifactId>jna-platform</artifactId> </exclusion> </exclusions>
</dependency> <!-- 重新引入版本-->
<dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>5.13.0</version>
</dependency> <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna-platform</artifactId> <version>5.13.0</version>
</dependency>