* @since UDK 3.1.0
*/
public static final XComponentContext bootstrap()
throws BootstrapException {
XComponentContext xContext = null;
try {
// create default local component context
XComponentContext xLocalContext =
createInitialComponentContext( null );
if ( xLocalContext == null )
throw new BootstrapException( "no local component context!" );
// find office executable relative to this class's class loader
String sOffice =
System.getProperty( "os.name" ).startsWith( "Windows" ) ?
"soffice.exe" : "soffice";
File fOffice = NativeLibraryLoader.getResource(
Bootstrap.class.getClassLoader(), sOffice );
if ( fOffice == null )
throw new BootstrapException( "no office executable found!" );
// create random pipe name
String sPipeName = "uno" +
Long.toString( (new Random()).nextLong() & 0x7fffffffffffffffL );
// create call with arguments
String[] cmdArray = new String[7];
cmdArray[0] = fOffice.getPath();
cmdArray[1] = "-nologo";
cmdArray[2] = "-nodefault";
cmdArray[3] = "-norestore";
cmdArray[4] = "-nocrashreport";
cmdArray[5] = "-nolockcheck";
cmdArray[6] = "-accept=pipe,name=" + sPipeName + ";urp;";
// start office process
Process p = Runtime.getRuntime().exec( cmdArray );
pipe( p.getInputStream(), System.out, "CO> " );
pipe( p.getErrorStream(), System.err, "CE> " );
// initial service manager
XMultiComponentFactory xLocalServiceManager =
xLocalContext.getServiceManager();
if ( xLocalServiceManager == null )
throw new BootstrapException( "no initial service manager!" );
// create a URL resolver
XUnoUrlResolver xUrlResolver =