[Libguestfs] How to run the java demo code contained in libguestfs package ???
Richard W.M. Jones
rjones at redhat.com
Mon May 23 08:10:31 UTC 2011
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);
}
}
}
More information about the Libguestfs
mailing list