[libvirt] RFC: libvirt java bindings based on JNA

I would like to get some comments on an initial cut of the java bindings on top of JNA[1]. They are not 100% complete (see below), but they are good enough to be criticized. In addition, if there are features additions to the API which people are interested in, I would appreciate the feedback on that. JNA is a java implementation of the Foreign Function Interface [2]. The main benefit is that it removes the need for all the nasty C glue code. What replaces it is pure java mapping files. If you look in the org.libvirt.jna package in the code, you will see that the 2928 lines of jni code have been replaced by 427 lines of java code. To be fair, some of the business logic from the C code is now in the org.libvirt package... but you get the point. The original java API has remained the same. The open issues with the code are: 1) Authorization callback has not been tested. 2) GetUUID is not returning the correct int array. 3) Find by UUID is not working These all are mapping issues to be worked out. The rest of the code should be working, but I would appreciate it being exercised. The main drawback to this approach is that it requires the use of java 1.6. I looked on EPEL, F10, and F11.. and java 1.6 and the JNA jar file are available so I did not believe this was an issue. I will send a patch stream to the list, but you can also get the code via an SRPM [3] or via github [4]. -- bk [1] https://jna.dev.java.net/ [2] http://en.wikipedia.org/wiki/Foreign_function_interface [3] http://bkearney.fedorapeople.org/libvirt-java-0.3.0pre-1.fc10.src.rpm [4] http://github.com/bkearney/libvirt-java/tree/jna

On Sat, Jul 25, 2009 at 07:56:36AM -0400, Bryan Kearney wrote:
I will send a patch stream to the list, but you can also get the code via an SRPM [3] or via github [4].
[snip]
FYI, I've just add the libvirt-java to the list or libvirt GIT repos that are automatically mirrored to gitorious.org to faciliate people who wish to publish personal development trees against up2date source. http://gitorious.org/libvirt/ Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Saturday 25 July 2009 13:56:36 Bryan Kearney wrote:
I would like to get some comments on an initial cut of the java bindings on top of JNA[1]. They are not 100% complete (see below), but they are good enough to be criticized. In addition, if there are features additions to the API which people are interested in, I would appreciate the feedback on that.
Thanks for your work! I pulled from git, it compiles fine when provided with jna.jar - couldn't find that except in my Eclipse 3.4 path. When using it with my tiny test application (which works fine with the JNI version), it first complains that /etc/pki/CA/cacert.pem can not be found. As I installed libvirt from source, it's in /usr/local/..., working fine with JNI. So I did a symlink workaround for now. But fixing that, it doesn't work either: libvir: error : invalid argument in could not parse connection URI exception caught:org.libvirt.LibvirtException: invalid argument in could not parse connection URI level:VIR_ERR_ERROR code:VIR_ERR_INVALID_ARG domain:VIR_FROM_NONE hasConn:false hasDom:false hasNet:false message:invalid argument in could not parse connection URI str1:invalid argument in %s str2:could not parse connection URI str3:null int1:0 int2:0 Code is: ... conn = new Connect("xen://node02", false); ... which works fine with JNI. When I use the test class (directly on a node where libvirtd is running, or remote, it doesn't matter), connections to the test driver are refused, although some test information seems to be gathered, and connecting with virsh works perfectly: node02:~# virsh --connect test:///default node02:~# java -cp libvirt-0.3.0pre.jar:jna.jar:. test libvir: Remote error : unable to connect to 'localhost': Connection refused exception caught:org.libvirt.LibvirtException: unable to connect to 'localhost': Connection refused level:VIR_ERR_ERROR code:VIR_ERR_SYSTEM_ERROR domain:VIR_FROM_REMOTE hasConn:false hasDom:false hasNet:false message:unable to connect to 'localhost': Connection refused str1:%s str2:unable to connect to 'localhost': Connection refused str3:null int1:-1 int2:-1 virNodeInfo.model:i686 virNodeInfo.memory:3145728 virNodeInfo.cpus:16 virNodeInfo.nodes:2 virNodeInfo.sockets:2 virNodeInfo.cores:2 virNodeInfo.threads:2 getHostName:node02.scripty.at getCapabilities:<capabilities> <host> <cpu> <arch>i686</arch> <features> <pae/> <nonpae/> </features> </cpu> <topology> <cells num='2'> <cell id='0'> <cpus num='8'> <cpu id='0'/> <cpu id='2'/> <cpu id='4'/> <cpu id='6'/> <cpu id='8'/> <cpu id='10'/> <cpu id='12'/> <cpu id='14'/> </cpus> </cell> <cell id='1'> <cpus num='8'> <cpu id='1'/> <cpu id='3'/> <cpu id='5'/> <cpu id='7'/> <cpu id='9'/> <cpu id='11'/> <cpu id='13'/> <cpu id='15'/> </cpus> </cell> </cells> </topology> </host> <guest> <os_type>hvm</os_type> <arch name='i686'> <wordsize>32</wordsize> <emulator>/usr/bin/test-hv</emulator> <domain type='test'> </domain> </arch> <features> <pae/> <nonpae/> </features> </guest> <guest> <os_type>xen</os_type> <arch name='i686'> <wordsize>32</wordsize> <emulator>/usr/bin/test-hv</emulator> <domain type='test'> </domain> </arch> <features> <pae/> <nonpae/> </features> </guest> </capabilities> getMaxVcpus:32 getType:Test getURI:test:// getVersion:2 getLibVirVersion:4006 conn.networkCreateXML: org.libvirt.Network@3d434234 conn.networkDefineXML: org.libvirt.Network@30f7f540 numOfDefinedNetworks:1 listDefinedNetworks:[Ljava.lang.String;@10b61fd1 -> deftest numOfNetworks:2 listNetworks:[Ljava.lang.String;@24e2dae9 -> createst -> default conn.domainDefineXML:org.libvirt.Domain@27ce2dd4 conn.domainCreateLinux:org.libvirt.Domain@5122cdb6 numOfDefinedDomains:1 listDefinedDomains:[Ljava.lang.String;@43ef9157 deftest numOfDomains:2 listDomains:[I@252f0999 -> 2 -> 1 networkLookupByName: deftest <============== FIXME ================> networkLookupByUUIDString: deftest virNetworkGetXMLDesc:<network> <name>deftest</name> <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e67</uuid> <forward dev='eth0' mode='nat'/> <bridge name='deftest' stp='on' forwardDelay='0' /> <ip address='192.168.88.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.88.128' end='192.168.88.253' /> </dhcp> </ip> </network> virNetworkGetAutostart:false virNetworkGetBridgeName:deftest virNetworkGetName:deftest virNetworkGetUUID:[I@443ecfff <============== FIXME ================> 004bffffff96ffffffe12d78ffffffc30f5affffffa5fffffff03cffffff87ffffffd21e67 virNetworkGetName:004b96e1-2d78-c30f-5aa5-f03c87d21e67 virNetworkDestroy: virNetworkCreate: virNetworkCreate (should error): libvir: Test error deftest: internal error Network is already running exception caught:org.libvirt.LibvirtException: internal error Network is already running level:VIR_ERR_ERROR code:VIR_ERR_INTERNAL_ERROR domain:VIR_FROM_TEST hasConn:false hasDom:false hasNet:false message:internal error Network is already running str1:internal error %s str2:Network is already running str3:null int1:0 int2:0 domainLookupByID: org.libvirt.Domain@a4a63d8 domainLookupByName: org.libvirt.Domain@19e0ff2f virDomainGetXMLDesc:<domain type='test' id='1'> <name>test</name> <uuid>d4bf820b-3c84-eebc-0947-98e00ed3c94f</uuid> <memory>8388608</memory> <currentMemory>2097152</currentMemory> <vcpu>2</vcpu> <os> <type arch='i686'>hvm</type> <boot dev='hd'/> </os> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> </devices> </domain> virDomainGetAutostart:false virDomainGetConnect:org.libvirt.Connect@29173ef virDomainGetID:1 virDomainGetInfo:state:VIR_DOMAIN_RUNNING maxMem:8388608 memory:2097152 nrVirtCpu:2 cpuTime:1248783222588997000 virDomainGetMaxMemory:8388608 libvir: error : this function is not supported by the hypervisor: virDomainGetMaxVcpus virDomainGetName:test virDomainGetOSType:linux virDomainGetSchedulerType:[Ljava.lang.String;@3a860d49 virDomainGetSchedulerParameters:[Lorg.libvirt.SchedParameter;@18872380 Uint:weight:1696596736 VIR_DOMAIN_SCHED_FIELD_UINT:weight:0 virDomainGetUUID:[I@502bb514 <============== FIXME ================> ffffffd4ffffffbfffffff820b3cffffff84ffffffeeffffffbc0947ffffff98ffffffe00effffffd3ffffffc94f virDomainGetUUIDString:d4bf820b-3c84-eebc-0947-98e00ed3c94f libvir: error : invalid connection pointer in virConnectGetHostname null Fini! Am I doing something wron

Thomas Treutner wrote:
On Saturday 25 July 2009 13:56:36 Bryan Kearney wrote:
I would like to get some comments on an initial cut of the java bindings on top of JNA[1]. They are not 100% complete (see below), but they are good enough to be criticized. In addition, if there are features additions to the API which people are interested in, I would appreciate the feedback on that.
Thanks for your work!
I pulled from git, it compiles fine when provided with jna.jar - couldn't find that except in my Eclipse 3.4 path.
When using it with my tiny test application (which works fine with the JNI version), it first complains that /etc/pki/CA/cacert.pem can not be found. As I installed libvirt from source, it's in /usr/local/..., working fine with JNI. So I did a symlink workaround for now.
Where did you see this complaint? Also.. what is your LD_LIBRARY_PATH set to when running this.
But fixing that, it doesn't work either:
libvir: error : invalid argument in could not parse connection URI exception caught:org.libvirt.LibvirtException: invalid argument in could not parse connection URI level:VIR_ERR_ERROR code:VIR_ERR_INVALID_ARG domain:VIR_FROM_NONE hasConn:false hasDom:false hasNet:false message:invalid argument in could not parse connection URI str1:invalid argument in %s str2:could not parse connection URI str3:null int1:0 int2:0
Code is: ... conn = new Connect("xen://node02", false); ...
which works fine with JNI.
Does conn = new Connect("xen://node2/", false) ; do any better?
When I use the test class (directly on a node where libvirtd is running, or remote, it doesn't matter), connections to the test driver are refused, although some test information seems to be gathered, and connecting with virsh works perfectly:
Acutally.. this is bad output. I bet I left the call with the defaultAuth in there. Can you verify that there are 2 open calls in the code I sent? Thanks!
node02:~# virsh --connect test:///default node02:~# java -cp libvirt-0.3.0pre.jar:jna.jar:. test libvir: Remote error : unable to connect to 'localhost': Connection refused exception caught:org.libvirt.LibvirtException: unable to connect to 'localhost': Connection refused level:VIR_ERR_ERROR code:VIR_ERR_SYSTEM_ERROR domain:VIR_FROM_REMOTE hasConn:false hasDom:false hasNet:false message:unable to connect to 'localhost': Connection refused str1:%s str2:unable to connect to 'localhost': Connection refused str3:null int1:-1 int2:-1
virNodeInfo.model:i686 virNodeInfo.memory:3145728 virNodeInfo.cpus:16 virNodeInfo.nodes:2 virNodeInfo.sockets:2 virNodeInfo.cores:2 virNodeInfo.threads:2 getHostName:node02.scripty.at getCapabilities:<capabilities>
<host> <cpu> <arch>i686</arch> <features> <pae/> <nonpae/> </features> </cpu> <topology> <cells num='2'> <cell id='0'> <cpus num='8'> <cpu id='0'/> <cpu id='2'/> <cpu id='4'/> <cpu id='6'/> <cpu id='8'/> <cpu id='10'/> <cpu id='12'/> <cpu id='14'/> </cpus> </cell> <cell id='1'> <cpus num='8'> <cpu id='1'/> <cpu id='3'/> <cpu id='5'/> <cpu id='7'/> <cpu id='9'/> <cpu id='11'/> <cpu id='13'/> <cpu id='15'/> </cpus> </cell> </cells> </topology> </host>
<guest> <os_type>hvm</os_type> <arch name='i686'> <wordsize>32</wordsize> <emulator>/usr/bin/test-hv</emulator> <domain type='test'> </domain> </arch> <features> <pae/> <nonpae/> </features> </guest>
<guest> <os_type>xen</os_type> <arch name='i686'> <wordsize>32</wordsize> <emulator>/usr/bin/test-hv</emulator> <domain type='test'> </domain> </arch> <features> <pae/> <nonpae/> </features> </guest>
</capabilities>
getMaxVcpus:32 getType:Test getURI:test:// getVersion:2 getLibVirVersion:4006 conn.networkCreateXML: org.libvirt.Network@3d434234 conn.networkDefineXML: org.libvirt.Network@30f7f540 numOfDefinedNetworks:1 listDefinedNetworks:[Ljava.lang.String;@10b61fd1 -> deftest numOfNetworks:2 listNetworks:[Ljava.lang.String;@24e2dae9 -> createst -> default conn.domainDefineXML:org.libvirt.Domain@27ce2dd4 conn.domainCreateLinux:org.libvirt.Domain@5122cdb6 numOfDefinedDomains:1 listDefinedDomains:[Ljava.lang.String;@43ef9157 deftest numOfDomains:2 listDomains:[I@252f0999 -> 2 -> 1 networkLookupByName: deftest <============== FIXME ================> networkLookupByUUIDString: deftest virNetworkGetXMLDesc:<network> <name>deftest</name> <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e67</uuid> <forward dev='eth0' mode='nat'/> <bridge name='deftest' stp='on' forwardDelay='0' /> <ip address='192.168.88.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.88.128' end='192.168.88.253' /> </dhcp> </ip> </network>
virNetworkGetAutostart:false virNetworkGetBridgeName:deftest virNetworkGetName:deftest virNetworkGetUUID:[I@443ecfff <============== FIXME ================> 004bffffff96ffffffe12d78ffffffc30f5affffffa5fffffff03cffffff87ffffffd21e67 virNetworkGetName:004b96e1-2d78-c30f-5aa5-f03c87d21e67 virNetworkDestroy: virNetworkCreate: virNetworkCreate (should error): libvir: Test error deftest: internal error Network is already running exception caught:org.libvirt.LibvirtException: internal error Network is already running level:VIR_ERR_ERROR code:VIR_ERR_INTERNAL_ERROR domain:VIR_FROM_TEST hasConn:false hasDom:false hasNet:false message:internal error Network is already running str1:internal error %s str2:Network is already running str3:null int1:0 int2:0
domainLookupByID: org.libvirt.Domain@a4a63d8 domainLookupByName: org.libvirt.Domain@19e0ff2f virDomainGetXMLDesc:<domain type='test' id='1'> <name>test</name> <uuid>d4bf820b-3c84-eebc-0947-98e00ed3c94f</uuid> <memory>8388608</memory> <currentMemory>2097152</currentMemory> <vcpu>2</vcpu> <os> <type arch='i686'>hvm</type> <boot dev='hd'/> </os> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> </devices> </domain>
virDomainGetAutostart:false virDomainGetConnect:org.libvirt.Connect@29173ef virDomainGetID:1 virDomainGetInfo:state:VIR_DOMAIN_RUNNING maxMem:8388608 memory:2097152 nrVirtCpu:2 cpuTime:1248783222588997000
virDomainGetMaxMemory:8388608 libvir: error : this function is not supported by the hypervisor: virDomainGetMaxVcpus virDomainGetName:test virDomainGetOSType:linux virDomainGetSchedulerType:[Ljava.lang.String;@3a860d49 virDomainGetSchedulerParameters:[Lorg.libvirt.SchedParameter;@18872380 Uint:weight:1696596736 VIR_DOMAIN_SCHED_FIELD_UINT:weight:0 virDomainGetUUID:[I@502bb514 <============== FIXME ================> ffffffd4ffffffbfffffff820b3cffffff84ffffffeeffffffbc0947ffffff98ffffffe00effffffd3ffffffc94f virDomainGetUUIDString:d4bf820b-3c84-eebc-0947-98e00ed3c94f libvir: error : invalid connection pointer in virConnectGetHostname null Fini!
Am I doing something wron

On Tuesday 28 July 2009 14:42:42 Bryan Kearney wrote:
Thomas Treutner wrote:
When using it with my tiny test application (which works fine with the JNI version), it first complains that /etc/pki/CA/cacert.pem can not be found. As I installed libvirt from source, it's in /usr/local/..., working fine with JNI. So I did a symlink workaround for now.
Where did you see this complaint? Also.. what is your LD_LIBRARY_PATH set to when running this.
The file not found was cacert.pem, not the *.so - so I don't think LD_LIBRARY_PATH matters here? Anyways, the problem about conn = new Connect("xen://node02", false); was my fault - I forgot wiping an old apt-installed version of libvirt before compiling libvirt-java-jna. It works now, but there seems to be a massive typo somewhere; when I start my small application, it can't find "liblibvirt.so" (sic!) and exits. # find /usr -name "libvirt.so*" /usr/local/lib/libvirt.so.0.6.5 /usr/local/lib/libvirt.so.0 /usr/local/lib/libvirt.so (ld cache is up to date, checked /etc/ld.so.cache) # ln -s /usr/local/lib/libvirt.so /usr/local/lib/liblibvirt.so # ldconfig ...and it works! ;-)
When I use the test class (directly on a node where libvirtd is running, or remote, it doesn't matter), connections to the test driver are refused, although some test information seems to be gathered, and connecting with virsh works perfectly:
Acutally.. this is bad output. I bet I left the call with the defaultAuth in there. Can you verify that there are 2 open calls in the code I sent?
This here? ... //For testing the authentication ConnectAuth defaultAuth = new ConnectAuthDefault(); try{ conn = new Connect("test+tcp://localhost/default", defaultAuth, 0); .... kr, thomas

Thomas Treutner wrote:
On Tuesday 28 July 2009 14:42:42 Bryan Kearney wrote:
Thomas Treutner wrote:
When using it with my tiny test application (which works fine with the JNI version), it first complains that /etc/pki/CA/cacert.pem can not be found. As I installed libvirt from source, it's in /usr/local/..., working fine with JNI. So I did a symlink workaround for now. Where did you see this complaint? Also.. what is your LD_LIBRARY_PATH set to when running this.
The file not found was cacert.pem, not the *.so - so I don't think LD_LIBRARY_PATH matters here?
Anyways, the problem about
conn = new Connect("xen://node02", false);
was my fault - I forgot wiping an old apt-installed version of libvirt before compiling libvirt-java-jna. It works now, but there seems to be a massive typo somewhere; when I start my small application, it can't find "liblibvirt.so" (sic!) and exits.
Really.. can you send me the output? What version of jna do you have?
# find /usr -name "libvirt.so*" /usr/local/lib/libvirt.so.0.6.5 /usr/local/lib/libvirt.so.0 /usr/local/lib/libvirt.so
(ld cache is up to date, checked /etc/ld.so.cache)
# ln -s /usr/local/lib/libvirt.so /usr/local/lib/liblibvirt.so # ldconfig
...and it works! ;-)
When I use the test class (directly on a node where libvirtd is running, or remote, it doesn't matter), connections to the test driver are refused, although some test information seems to be gathered, and connecting with virsh works perfectly: Acutally.. this is bad output. I bet I left the call with the defaultAuth in there. Can you verify that there are 2 open calls in the code I sent?
This here?
... //For testing the authentication ConnectAuth defaultAuth = new ConnectAuthDefault();
try{ conn = new Connect("test+tcp://localhost/default", defaultAuth, 0); ....
Yes.. this was causing hte failure.. if you comment this out (I am still debugging this) you should see it run with no failures. -- bk

On Wednesday 29 July 2009 13:49:45 Bryan Kearney wrote:
Thomas Treutner wrote:
On Tuesday 28 July 2009 14:42:42 Bryan Kearney wrote:
Thomas Treutner wrote:
When using it with my tiny test application (which works fine with the JNI version), it first complains that /etc/pki/CA/cacert.pem can not be found. As I installed libvirt from source, it's in /usr/local/..., working fine with JNI. So I did a symlink workaround for now.
Where did you see this complaint?
Hm, I really cannot reproduce it anymore. Most probably it was caused by my libvirt-mixup.
Also.. what is your LD_LIBRARY_PATH set to when running this.
# cat /etc/ld.so.conf.d/* /usr/local/lib /usr/local/lib /usr/lib/kde4/lib # libc default configuration /usr/local/lib # Multiarch support /lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu
The file not found was cacert.pem, not the *.so - so I don't think LD_LIBRARY_PATH matters here?
Anyways, the problem about
conn = new Connect("xen://node02", false);
was my fault - I forgot wiping an old apt-installed version of libvirt before compiling libvirt-java-jna. It works now, but there seems to be a massive typo somewhere; when I start my small application, it can't find "liblibvirt.so" (sic!) and exits.
Really.. can you send me the output?
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libvirt': liblibvirt.so: cannot open shared object file: No such file or directory at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:145) at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:188) at com.sun.jna.Library$Handler.<init>(Library.java:123) at com.sun.jna.Native.loadLibrary(Native.java:255) at com.sun.jna.Native.loadLibrary(Native.java:241) at org.libvirt.jna.Libvirt.<clinit>(Unknown Source) at org.libvirt.Connect.<clinit>(Unknown Source) at MyTest.main(MyTest.java:13) MyTest.java:13: conn = new Connect("xen://node01/", false);
What version of jna do you have?
# cat META-INF/MANIFEST.MF Manifest-Version: 1.0 Ant-Version: Apache Ant 1.7.0 Created-By: 1.5.0_16-133 (Apple Inc.) Main-Class: com.sun.jna.Native Name: com/sun/jna/ Implementation-Title: com.sun.jna Implementation-Vendor: JNA Development Team Implementation-Version: 3.0.9 b0 Specification-Title: Java Native Access (JNA) Specification-Vendor: JNA Development Team Specification-Version: 3 It ist part of Eclipse, now downloaded 3.2.1 from jna.dev.java.net, with same results: Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libvirt': liblibvirt.so: cannot open shared object file: No such file or directory at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:160) at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:228) at com.sun.jna.Library$Handler.<init>(Library.java:140) at com.sun.jna.Native.loadLibrary(Native.java:372) at com.sun.jna.Native.loadLibrary(Native.java:357) at org.libvirt.jna.Libvirt.<clinit>(Unknown Source) at org.libvirt.Connect.<clinit>(Unknown Source) at MyTest.main(MyTest.java:13) hth&tia, thomas

Can you try the new release? It is cleaned up.. and should be easier to consume. Let me know if there are issues. -- bk Thomas Treutner wrote:
On Wednesday 29 July 2009 13:49:45 Bryan Kearney wrote:
Thomas Treutner wrote:
On Tuesday 28 July 2009 14:42:42 Bryan Kearney wrote:
Thomas Treutner wrote:
When using it with my tiny test application (which works fine with the JNI version), it first complains that /etc/pki/CA/cacert.pem can not be found. As I installed libvirt from source, it's in /usr/local/..., working fine with JNI. So I did a symlink workaround for now. Where did you see this complaint?
Hm, I really cannot reproduce it anymore. Most probably it was caused by my libvirt-mixup.
Also.. what is your LD_LIBRARY_PATH set to when running this.
# cat /etc/ld.so.conf.d/* /usr/local/lib /usr/local/lib /usr/lib/kde4/lib # libc default configuration /usr/local/lib # Multiarch support /lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu
The file not found was cacert.pem, not the *.so - so I don't think LD_LIBRARY_PATH matters here?
Anyways, the problem about
conn = new Connect("xen://node02", false);
was my fault - I forgot wiping an old apt-installed version of libvirt before compiling libvirt-java-jna. It works now, but there seems to be a massive typo somewhere; when I start my small application, it can't find "liblibvirt.so" (sic!) and exits. Really.. can you send me the output?
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libvirt': liblibvirt.so: cannot open shared object file: No such file or directory at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:145) at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:188) at com.sun.jna.Library$Handler.<init>(Library.java:123) at com.sun.jna.Native.loadLibrary(Native.java:255) at com.sun.jna.Native.loadLibrary(Native.java:241) at org.libvirt.jna.Libvirt.<clinit>(Unknown Source) at org.libvirt.Connect.<clinit>(Unknown Source) at MyTest.main(MyTest.java:13)
MyTest.java:13: conn = new Connect("xen://node01/", false);
What version of jna do you have?
# cat META-INF/MANIFEST.MF Manifest-Version: 1.0 Ant-Version: Apache Ant 1.7.0 Created-By: 1.5.0_16-133 (Apple Inc.) Main-Class: com.sun.jna.Native
Name: com/sun/jna/ Implementation-Title: com.sun.jna Implementation-Vendor: JNA Development Team Implementation-Version: 3.0.9 b0 Specification-Title: Java Native Access (JNA) Specification-Vendor: JNA Development Team Specification-Version: 3
It ist part of Eclipse, now downloaded 3.2.1 from jna.dev.java.net, with same results:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libvirt': liblibvirt.so: cannot open shared object file: No such file or directory at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:160) at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:228) at com.sun.jna.Library$Handler.<init>(Library.java:140) at com.sun.jna.Native.loadLibrary(Native.java:372) at com.sun.jna.Native.loadLibrary(Native.java:357) at org.libvirt.jna.Libvirt.<clinit>(Unknown Source) at org.libvirt.Connect.<clinit>(Unknown Source) at MyTest.main(MyTest.java:13)
hth&tia, thomas

On Thursday 30 July 2009 13:57:44 Thomas Treutner wrote:
On Thursday 30 July 2009 03:30:20 Bryan Kearney wrote:
Can you try the new release? It is cleaned up.. and should be easier to consume. Let me know if there are issues.
Thanks, works fine so far (liblibvirt.so issue is gone).
Sorry for the mixup, but I wasn't using the new version, Eclipse was accidentially configured for JNI version. It still doesn't work, so I looked in the code and did a quick experiment: src/main/java/org/libvirt/jna/Libvirt.java:23: -Libvirt INSTANCE = (Libvirt) Native.loadLibrary("libvirt", Libvirt.class); +Libvirt INSTANCE = (Libvirt) Native.loadLibrary("virt", Libvirt.class); and it works (without any symlinks hacks, of course). I don't have any experience with JNA, but I assume that somewhere a "lib" is being prepended and therefore "libvirt" is over-specified. What I still don't understand is my it is presumably working for you, and not for me: JNA 3.2.1 $ java -version java version "1.6.0_14" Java(TM) SE Runtime Environment (build 1.6.0_14-b08) Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode) $ javac -version javac 1.6.0_14 btw, I don't see a JNA-branch in git://libvirt.org/libvirt-java.git anymore - is JNI-version now obsolete? kr, thomas

Thomas Treutner wrote:
On Thursday 30 July 2009 13:57:44 Thomas Treutner wrote:
On Thursday 30 July 2009 03:30:20 Bryan Kearney wrote:
Can you try the new release? It is cleaned up.. and should be easier to consume. Let me know if there are issues. Thanks, works fine so far (liblibvirt.so issue is gone).
Sorry for the mixup, but I wasn't using the new version, Eclipse was accidentially configured for JNI version. It still doesn't work, so I looked in the code and did a quick experiment:
src/main/java/org/libvirt/jna/Libvirt.java:23: -Libvirt INSTANCE = (Libvirt) Native.loadLibrary("libvirt", Libvirt.class); +Libvirt INSTANCE = (Libvirt) Native.loadLibrary("virt", Libvirt.class);
and it works (without any symlinks hacks, of course). I don't have any experience with JNA, but I assume that somewhere a "lib" is being prepended and therefore "libvirt" is over-specified.
What I still don't understand is my it is presumably working for you, and not for me:
JNA 3.2.1
$ java -version java version "1.6.0_14" Java(TM) SE Runtime Environment (build 1.6.0_14-b08) Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode) $ javac -version javac 1.6.0_14
btw, I don't see a JNA-branch in git://libvirt.org/libvirt-java.git anymore - is JNI-version now obsolete?
kr, thomas Let me ask the JNA guys. I am on 3.0.9 of JNA.. prehaps something changed.
-- bk

Thomas Treutner wrote:
On Thursday 30 July 2009 13:57:44 Thomas Treutner wrote:
On Thursday 30 July 2009 03:30:20 Bryan Kearney wrote:
Can you try the new release? It is cleaned up.. and should be easier to consume. Let me know if there are issues. Thanks, works fine so far (liblibvirt.so issue is gone).
Sorry for the mixup, but I wasn't using the new version, Eclipse was accidentially configured for JNI version. It still doesn't work, so I looked in the code and did a quick experiment:
src/main/java/org/libvirt/jna/Libvirt.java:23: -Libvirt INSTANCE = (Libvirt) Native.loadLibrary("libvirt", Libvirt.class); +Libvirt INSTANCE = (Libvirt) Native.loadLibrary("virt", Libvirt.class);
per a discussion with the JNA guys, they first try the name, and then prepend lib onto it. So.. if libvirt.so is in your LD_LIBRARY_PATH both should work. However, I have commited a change to only load lib. Go ahead and try that.
and it works (without any symlinks hacks, of course). I don't have any experience with JNA, but I assume that somewhere a "lib" is being prepended and therefore "libvirt" is over-specified.
What I still don't understand is my it is presumably working for you, and not for me:
JNA 3.2.1
$ java -version java version "1.6.0_14" Java(TM) SE Runtime Environment (build 1.6.0_14-b08) Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode) $ javac -version javac 1.6.0_14
btw, I don't see a JNA-branch in git://libvirt.org/libvirt-java.git anymore - is JNI-version now obsolete?
Yes.. 0.3.0 will be based on JNA. I will actively make changes to the 0.3.0 bits. -- bk
participants (3)
-
Bryan Kearney
-
Daniel P. Berrange
-
Thomas Treutner