OO-Snippets: Bootstrap OpenOffice

Commons

Keywordsbootstrap, start
LanguageJava
ApplicationOffice
AuthorsTobias Krais (www.design-to-use.de) (initial)
Supported Versions2.0.x  
Supported OSAll  
QuestionHow to bootstrap OpenOffice.org?
Answer

This method bootstraps OpenOffice.

If you don't want to add all the UNO jars to your classpath do following:

1. Add these files to your jar (you find them in a SDK subfolder):

com/sun/star/lib/loader/Loader$CustomURLClassLoader.class

com/sun/star/lib/loader/Loader.class

com/sun/star/lib/loader/InstallationFinder$StreamGobbler.class

com/sun/star/lib/loader/InstallationFinder.class

com/sun/star/lib/loader/WinRegKey.class

com/sun/star/lib/loader/WinRegKeyException.class

win/unowinreg.dll

2. Create a MANIFEST.MF file for your jar and use it when creating

the jar. The MANIFEST.MF must look like:

Main-Class: com.sun.star.lib.loader.Loader

Name: com/sun/star/lib/loader/Loader.class

Application-Class: my.package.MyClass

Application-Name: my/package/MyClass.class

3. Start your application using e.g. this command:

java -jar myjar.jar

Code-Snippet-Listing (snippet-source)

import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.comp.helper.BootstrapException;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.XComponentContext;

/**
 * This method bootstraps a OpenOffice and returns it's Desktop.
 * 
 * @return
 */
public void bootstrapOpenOffice()
{
	XComponentContext xRemoteContext = null;
	try
	{
		// Connect or start a OpenOffice instance
		xRemoteContext = Bootstrap.bootstrap();
	}
	catch (BootstrapException e) {
	}

	// get OO desktop
	XMultiComponentFactory xRemoteServiceManager = 
			xRemoteContext.getServiceManager();

	Object desktop = null;
	try	{
		desktop = xRemoteServiceManager.createInstanceWithContext(
				"com.sun.star.frame.Desktop", xRemoteContext
		);
	}
	catch (Exception e)	{
	}
}

Changelog

DateUserModification
2006-12-11tobiaskraisLinked resources.
2006-03-27tobiaskraisAdded the hints for usage without classpath.
2006-03-20Initial version

and