Page 1 of 1
java xpcom sample
Posted: 22. Jan 2009, 17:32
by elombert
Hi all!
I have been looking all over the internet for a few days for an example on how to use VBox using XPCOM from a Java program (not using ws).
Does anyone have an example on this that is willing to share, publish or at least point us to it?
Thanks a lot!
Ellis Lombert
Posted: 22. Jan 2009, 18:22
by TerryE
Examples like this are thin, I'm sorry to say. There are some skeleton ones in the SDK. Try googling for some of the class names. I also use the code from OSE source (Mainly VBoxManage.cpp) to see how to put together the API sequences. OK this is C++, but you can still do the mapping to Java.
Posted: 23. Jan 2009, 19:37
by elombert
The following java code throws the exception:
Error al listar las VMs
org.mozilla.xpcom.XPCOMException: The function "createInstanceByContractID" returned an error condition (0x80040154)
at org.mozilla.xpcom.internal.XPCOMJavaProxy.callXPCOMMethod(Native Method)
at org.mozilla.xpcom.internal.XPCOMJavaProxy.invoke(XPCOMJavaProxy.java:143)
at $Proxy1.createInstanceByContractID(Unknown Source)
at EjeVBox.main(EjeVBox.java:25)
Can any one help me to find out where is the error here?
The code that I am trying to run is this one:
Code: Select all
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.virtualbox.*;
import org.mozilla.interfaces.*;
import com.sun.xml.internal.bind.v2.runtime.reflect.ListIterator;
import com.sun.xml.ws.commons.virtualbox.*;
public class EjeVBox {
public static void main(String args[])
{
int hr = 0;
nsIServiceManager sm;
org.mozilla.xpcom.Mozilla mozilla = org.mozilla.xpcom.Mozilla.getInstance();
mozilla.initialize(new File("/home/box1/workspace/EjeXul/native/linux/xulrunner/"));
sm = mozilla.getServiceManager();
try{
nsIComponentManager cm = mozilla.getComponentManager();
String NS_VIRTUALBOX_CONTRACTID = "@virtualbox.org/VirtualBox;1";
IVirtualBox virtualBox = (IVirtualBox)cm.createInstanceByContractID(NS_VIRTUALBOX_CONTRACTID, null, null);
listVMs(virtualBox);
mozilla.shutdownXPCOM(sm);
}catch(Exception e){ System.out.println("Error al listar las VMs "); e.printStackTrace(); }
}
static void listVMs(IVirtualBox virtualBox)
{
List<IMachine> lst = new ArrayList<IMachine>();
lst = virtualBox.getMachines2();
if (lst == null) return;
ListIterator<IMachine> it = (ListIterator<IMachine>) lst.listIterator();
try{
while (it.hasNext())
{
IMachine machine = it.next();
if (machine != null)
{
System.out.println("Description: "+machine.getDescription());
System.out.println("GuestProperty: "+machine.getGuestPropertyNotificationPatterns());
System.out.println("Hardware version: "+machine.getHardwareVersion());
System.out.println("Name: "+machine.getName());
System.out.println("Log folder: "+machine.getLogFolder());
System.out.println("Session type: "+machine.getSessionType());
}
}
} catch(Exception ee){ ee.printStackTrace(); }
}
}
Posted: 24. Jan 2009, 18:23
by TerryE
This is really one to post on the developers mailing list. However, as far as I read this, in the SDK there are two API interfaces: the webservice and the xpcom interfaces. The kit include the java bindings for the former but not the latter and it is the latter that you are trying to use. The VBox XPCOM is an implementation of Mozilla's XPCOM but it is not the same implementation. You seem to be calling the mozilla implementation which will connect to the Mozilla XPCOM broker, and not the VBox broker. Hence I would expect it to through an unknown source.
Of course I might be entirely wrong. You need to check this with the developers.
Posted: 24. Jan 2009, 19:00
by nike
Java bindings are currently only supported for webservices flavour of the API. The only language (other than C++) that supports XPCOM bindings is Python.
Are there any specific reasons why you cannot use webservices?
Posted: 28. Jan 2009, 15:13
by elombert
Hello guys!
Thanks a lot for your answer.
What I'm trying to do is to embed a virtual machine within a java container using a frame, a panel, a canvas or something like that. I would like to do something like that you can do with JVLC to embed a VLC player inside a panel.
Thanks again!
Posted: 29. Jan 2009, 01:08
by TerryE
To do something like that you will need to write your own custom display handler alongside the existing ones. The VBox architecture allows you to do this -- which is why you can choose between headless and normal integrated displays, but this is a major piece of development.
Re: java xpcom sample
Posted: 7. Oct 2009, 23:09
by mikebarnacle
I need access to the framebuffer in Java. The webservices API doesn't support this... What can I do?