public static void main(String[] args) {
try {
XComponentContext xcomponentcontext = Bootstrap.createInitialComponentContext( null );
// initial serviceManager
XMultiComponentFactory xLocalServiceManager = xcomponentcontext.getServiceManager();
// create a connector, so that it can contact the office
XUnoUrlResolver urlResolver
= UnoUrlResolver.create( xcomponentcontext );
Object initialObject = urlResolver.resolve(
"uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" );
XMultiComponentFactory xOfficeFactory= UnoRuntime.queryInterface(
XMultiComponentFactory.class, initialObject );
// retrieve the component context (it's not yet exported from the office)
// Query for the XPropertySet interface.
XPropertySet xProperySet = UnoRuntime.queryInterface(
XPropertySet.class, xOfficeFactory);
// Get the default context from the office server.
Object oDefaultContext = xProperySet.getPropertyValue( "DefaultContext" );
// Query for the interface XComponentContext.
XComponentContext xOfficeComponentContext = UnoRuntime.queryInterface(
XComponentContext.class, oDefaultContext );
// now create the desktop service
// NOTE: use the office component context here !
Object oDesktop = xOfficeFactory.createInstanceWithContext("com.sun.star.frame.Desktop",
xOfficeComponentContext );
} catch(com.sun.star.connection.NoConnectException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} catch(com.sun.star.connection.ConnectionSetupException ce) {