我在使用 Libvirt API 连接到 QEMU 时遇到问题,代码如下:
import org.libvirt.Connect;
import org.libvirt.ConnectAuth;
import org.libvirt.ConnectAuthDefault;
import org.libvirt.LibvirtException;
import org.libvirt.NodeInfo;
public class Main
{
public static void main(String[] args)
{
System.setProperty("jna.library.path", "/home/johann/workspace/LibvirtTest/lib");
try {
ConnectAuth ca = new ConnectAuthDefault();
Connect conn = new Connect("qemu+tcp://192.168.122.0/24", ca, 0);
NodeInfo ni = conn.nodeInfo();
System.out.println("model: " + ni.model + " mem(kb):" + ni.memory);
} catch(LibvirtException le) {
le.printStackTrace();
}
}
}
问题出在线路上
Connect conn = new Connect("qemu+tcp://192.168.122.0/24", ca, 0);
它使编译器抛出此异常
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.jna.Native.pointerSize()I
at com.sun.jna.Native.pointerSize(Native Method)
at com.sun.jna.Native.<clinit>(Native.java:88)
at org.libvirt.jna.Libvirt.<clinit>(Unknown Source)
at org.libvirt.Connect.<clinit>(Unknown Source)
at Main.main(Main.java:16)
我在 Virtual Machine Manager localhost QEMU 详细信息中找到了这个地址和端口,但它似乎不起作用......
提前致谢!:)