我有两个项目,一个项目使用 oshi 来获取我的 cpu 信息,并且运行良好。
public class MyTest {
public static void main(String[] args) {
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
CentralProcessor cpu = hal.getProcessor();
System.out.println("cpu.getLogicalProcessorCount(): " + cpu.getLogicalProcessorCount());
System.out.println("cpu.getCurrentFreq(): " + cpu.getCurrentFreq());
System.out.println("hal.getMemory(): " + hal.getMemory());
}
但另一个项目使用oshi来获取我的cpu信息,代码几乎相同,但抛出异常。
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/herrhu/Library/Caches/JNA/temp/jna7537516652503870093.tmp: dlopen(/Users/herrhu/Library/Caches/JNA/temp/jna7537516652503870093.tmp, 1): no suitable image found. Did find:
/Users/herrhu/Library/Caches/JNA/temp/jna7537516652503870093.tmp: no matching architecture in universal wrapper
/Users/herrhu/Library/Caches/JNA/temp/jna7537516652503870093.tmp: no matching architecture in universal wrapper
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1950)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1832)
at java.lang.Runtime.load0(Runtime.java:811)
at java.lang.System.load(System.java:1088)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1018)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:988)
at com.sun.jna.Native.<clinit>(Native.java:195)
at com.sun.jna.platform.mac.SystemB.<clinit>(SystemB.java:40)
at oshi.util.platform.mac.SysctlUtil.sysctl(SysctlUtil.java:61)
at oshi.hardware.platform.mac.MacCentralProcessor.initProcessorCounts(MacCentralProcessor.java:128)
at oshi.hardware.common.AbstractCentralProcessor.<init>(AbstractCentralProcessor.java:74)
at oshi.hardware.platform.mac.MacCentralProcessor.<init>(MacCentralProcessor.java:61)
at oshi.hardware.platform.mac.MacHardwareAbstractionLayer.createProcessor(MacHardwareAbstractionLayer.java:60)
at oshi.util.Memoizer$1.get(Memoizer.java:87)
at oshi.hardware.common.AbstractHardwareAbstractionLayer.getProcessor(AbstractHardwareAbstractionLayer.java:68)
at com.clougence.cloudcanal.sidecar.shell.OshiTest2.main(OshiTest2.java:28)
进程以退出代码 1 结束
我不知道为什么不同项目中相同的代码有不同的结果。并且两个项目中的依赖项是相同的。 enter image description here