libvirt

时间:2016-04-24 04:26:46

标签: java java-native-interface qemu libvirt

我正在尝试使用

中的代码通过java连接kvm

https://libvirt.org/java.html

当我尝试连接时,我收到以下错误

2016-04-23 21:18:17.960 ERROR 6359 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.UnsatisfiedLinkError: Unable to load library 'virt': libvirt.so: cannot open shared object file: No such file or directory] with root cause

java.lang.UnsatisfiedLinkError: Unable to load library 'virt': libvirt.so: cannot open shared object file: No such file or directory
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:166) ~[jna-3.3.0.jar!/:3.3.0 (b0)]
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:239) ~[jna-3.3.0.jar!/:3.3.0 (b0)]
    at com.sun.jna.Library$Handler.<init>(Library.java:140) ~[jna-3.3.0.jar!/:3.3.0 (b0)]
    at com.sun.jna.Native.loadLibrary(Native.java:393) ~[jna-3.3.0.jar!/:3.3.0 

我在ubuntu上安装了libvirt

 libvirtd --version
libvirtd (libvirt) 1.2.2

我的build.gradle是

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.libvirt:libvirt:0.5.1')
    compile('net.java.dev.jna:jna:3.3.0')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
}

有没有人遇到类似的问题。

1 个答案:

答案 0 :(得分:0)

因为你在Linux上,当你的应用程序试图加载像.so这样的本机库时会抛出这个异常。在这种情况下,JVM同时查看PATH环境变量和java.library.path系统属性。 要修复此异常,您需要为您尝试加载的库设置路径。就像你为java设置路径一样。