关于no office executable found!解决方法

来源:互联网 发布:js继承的几种方式比较 编辑:程序博客网 时间:2024/06/06 01:22

  笔者写了一个简单新建swriter的代码

com.sun.star.uno.XComponentContext xContext = null;
        
        try {
            // get the remote office component context
            xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
            System.out.println("Connected to a running office ...");

            // get the rmeote service manger
            com.sun.star.lang.XMultiComponentFactory xMCF =
                xContext.getServiceManager();

            // create a new instance of the desktop
            Object oDesktop = xMCF.createInstanceWithContext(
                                        "com.sun.star.frame.Desktop", xContext);

            // get the component laoder from the desktop to create a new
            // text document
            com.sun.star.frame.XComponentLoader xCLoader =
                (com.sun.star.frame.XComponentLoader)
                UnoRuntime.queryInterface(
                    com.sun.star.frame.XComponentLoader.class,oDesktop);
            com.sun.star.beans.PropertyValue [] szEmptyArgs =
                new com.sun.star.beans.PropertyValue [0];
            String strDoc = "private:factory/swriter";

            System.out.println("create new text document");
            
            com.sun.star.lang.XComponent xComp = xCLoader.loadComponentFromURL(
                strDoc, "_blank", 0, szEmptyArgs);
        }
        catch( Exception e) {
            e.printStackTrace(System.err);
            System.exit(1);
        }

运行后会报错如下:

com.sun.star.comp.helper.BootstrapException: no office executable found!


解决方案如下:

第一步 下载bootstrapconnector.jar,链接地址为 http://user.services.openoffice.org/en/forum/download/file.php?id=836&sid=12df5c8cdc4d853aa8a6fc87071f922f

第二步 把下载好的bootstrapconnector.jar包放到你安装office后juh.jar的地方

第三步 修改相应的源代码

            xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();修改为:

            String oooExeFolder = "C:/Program Files/NeoShineOffice 5/program/";

           xContext = BootstrapSocketConnector.bootstrap(oooExeFolder);


之后的代码可以保持即可新建一篇字处理文档