毛宏
2011-May-23 07:05 UTC
[Libguestfs] How to run the java demo code contained in libguestfs package ???
Hi all, I would like to use libguestfs to manage the virtual disk images of virtual machines on XenServer, which is a virtualization platform. When I try to do some test of the Java codes contained in the libguestfs package, the following error promped up: Exception in thread "main" java.lang.UnsatisfiedLinkError: no guestfs_jni in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at com.redhat.et.libguestfs.GuestFS.<clinit>(GuestFS.java:44) at test.GuestFS005Load.main(GuestFS005Load.java:27) It seems that I need to build guestfs_jni before I could use libguestfs through Java. But I am not clear how to get this "guestfs_jni"....... Does anybody know how to fix this problem? Thank you very very much! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://listman.redhat.com/archives/libguestfs/attachments/20110523/616f2073/attachment.htm>
Richard W.M. Jones
2011-May-23 08:10 UTC
[Libguestfs] How to run the java demo code contained in libguestfs package ???
On Mon, May 23, 2011 at 03:05:28PM +0800, ?? wrote:> I would like to use libguestfs to manage the virtual disk images of > virtual machines on XenServer, which is a virtualization platform.What version of libguestfs and where did you get it from?> When I try to do some test of the Java codes contained in the libguestfs package, the following error promped up: > > Exception in thread "main" java.lang.UnsatisfiedLinkError: no guestfs_jni in java.library.path > at java.lang.ClassLoader.loadLibrary(Unknown Source) > at java.lang.Runtime.loadLibrary0(Unknown Source) > at java.lang.System.loadLibrary(Unknown Source) > at com.redhat.et.libguestfs.GuestFS.<clinit>(GuestFS.java:44) > at test.GuestFS005Load.main(GuestFS005Load.java:27) > > It seems that I need to build guestfs_jni before I could use libguestfs through Java. But I am not clear how to get this "guestfs_jni"....... > Does anybody know how to fix this problem? Thank you very very much!If the *.so file is in some non-standard place, then you may need to define java.library.path to be the directory containing libguestfs_jni.so.1. For example: java -Djava.library.path=/path/to/library Test You may also need to set your classpath to contain the jar file. On a Fedora host using the libguestfs-java Fedora package, I can run libguestfs like this [see attachment for test program]: $ CLASSPATH=/usr/share/java/libguestfs-1.11.8.jar javac Test.java $ CLASSPATH=/usr/share/java/libguestfs-1.11.8.jar:. java Test $ virt-filesystems -a test.img --all --long Name Type VFS Label Size Parent /dev/VG/LV1 filesystem ext2 - 209715200 - /dev/VG/LV2 filesystem unknown - 209715200 - /dev/VG/LV1 lv - - 209715200 /dev/VG /dev/VG/LV2 lv - - 209715200 /dev/VG /dev/VG vg - - 520093696 - /dev/sda pv - - 520093696 - /dev/sda device - - 524288000 - Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw -------------- next part -------------- import java.io.*; import java.util.Map; import com.redhat.et.libguestfs.*; public class Test { public static void main (String[] argv) { try { // Delete any previous test file if one was left around. File old = new File ("test.img"); old.delete (); RandomAccessFile f = new RandomAccessFile ("test.img", "rw"); f.setLength (500 * 1024 * 1024); f.close (); GuestFS g = new GuestFS (); g.add_drive ("test.img"); g.launch (); g.pvcreate ("/dev/sda"); g.vgcreate ("VG", new String[] {"/dev/sda"}); g.lvcreate ("LV1", "VG", 200); g.lvcreate ("LV2", "VG", 200); g.mkfs ("ext2", "/dev/VG/LV1"); g.close (); } catch (Exception exn) { System.err.println (exn); System.exit (1); } } }
Richard W.M. Jones
2011-May-23 09:12 UTC
[Libguestfs] How to run the java demo code contained inlibguestfs package ???
[Please keep replies on the list] On Mon, May 23, 2011 at 04:44:48PM +0800, ?? wrote:> Thanks, I am using libguestfs-1.10.3, the stable release. But I > can't find the libguestfs_jni.so.1 or the jar file from the package, > where can I get one ?Are you compiling from source? In the standard build, libtool puts the libguestfs_jni.so* files in "java/.libs" so you would use: java -Djava.library.path=.libs t/GuestFS005Load (See java/run-java/tests) The jar file should be built in the java/ directory. However you don't need it when running the tests because the JVM can find the separate *.class files it needs from the current directory. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top