项目场景:
使用sigar获取服务器信息
问题描述:
java执行报错
1 [main] DEBUG Sigar - no libsigar-amd64-linux.so in java.library.path
org.hyperic.sigar.SigarException: no libsigar-amd64-linux.so in java.library.path
at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:172)
at org.hyperic.sigar.Sigar.<clinit>(Sigar.java:100)
at com.cloud.entity.SigarUtil.<clinit>(SigarUtil.java:11)
at com.cloud.GetLinuxInformationMain.main(GetLinuxInformationMain.java:24)
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:483)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Exception in thread "main" java.lang.reflect.InvocationTargetException
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:483)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.UnsatisfiedLinkError: org.hyperic.sigar.Mem.gather(Lorg/hyperic/sigar/Sigar;)V
at org.hyperic.sigar.Mem.gather(Native Method)
at org.hyperic.sigar.Mem.fetch(Mem.java:30)
at org.hyperic.sigar.Sigar.getMem(Sigar.java:304)
at com.cloud.entity.SigarUtil.memory(SigarUtil.java:148)
at com.cloud.GetLinuxInformationMain.main(GetLinuxInformationMain.java:24)
... 8 more
原因分析:
需要用到库
sigar-amd64-winnt.dll
libsigar-amd64-linux.so
libsigar-x86-linux.so
解决方案:
- windows需要用到库:sigar-amd64-winnt.dll 放入路径:C:\Windows\System32
- linux需要用到库:libsigar-amd64-linux.so和libsigar-x86-linux.so 放入/usr/lib64?
如linux无root权限,可以指定:
在linux执行jar执行时指定库:java -Djava.library.path=指定库所在的目录 -jar cloud.jar?
|