java xpcom sample

This is for discussing general topics about how to use VirtualBox.
Post Reply
elombert
Posts: 3
Joined: 22. Jan 2009, 17:09

java xpcom sample

Post 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
TerryE
Volunteer
Posts: 3572
Joined: 28. May 2008, 08:40
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
Contact:

Post 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.
Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
elombert
Posts: 3
Joined: 22. Jan 2009, 17:09

Post 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(); }
	}
}
TerryE
Volunteer
Posts: 3572
Joined: 28. May 2008, 08:40
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
Contact:

Post 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.
Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
nike
Posts: 47
Joined: 7. Jul 2008, 00:00
Primary OS: Ubuntu 8.04
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: OS/2 1.2, Windows 3.11, OSX
Location: SPB
Contact:

Post 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?
elombert
Posts: 3
Joined: 22. Jan 2009, 17:09

Post 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!
TerryE
Volunteer
Posts: 3572
Joined: 28. May 2008, 08:40
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
Contact:

Post 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.
Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
mikebarnacle
Posts: 2
Joined: 6. Oct 2009, 05:09
Primary OS: MS Windows XP
VBox Version: OSE Debian
Guest OSses: SPAM_SEARCH

Re: java xpcom sample

Post by mikebarnacle »

I need access to the framebuffer in Java. The webservices API doesn't support this... What can I do?
Post Reply