2

i'm having a problem with connecting to QEMU with Libvirt API, here is the code:

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();
    }
  }
}

The problem is with the line

Connect conn = new Connect("qemu+tcp://192.168.122.0/24", ca, 0);

It makes the compiler throws this exception

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)

I have found this address and port in the Virtual Machine Manager localhost QEMU details, but it doesn't seems to work...

Thanks in advance! :)

Johann Gomes
  • 3,813
  • 5
  • 23
  • 25
  • answer of this question is explained in this thread http://stackoverflow.com/questions/33208577/setup-libvirt-java-development-environment-on-linux-machine – MirzaOsama Wahid Oct 27 '15 at 09:56

1 Answers1

1

It seems the address is not ok.

"qemu+type://loginname@ip:port/system" would be right.

In your case it seems 192.168.122.0/24 is an ip and subnetmask because /24 equals subnetmask 255.255.255.0 and doesn't belong here... If it is a port you have to write :24. Also /system is missing

qemu+tcp://192.168.122.0:24/system should do the job - if not try two things:

1st Get rid of :24 and test

2nd Add username as shown above and test

One of this possibilities should work assuming the rest of your code is correct. Have fun!

eye
  • 450
  • 1
  • 4
  • 14