solution “no office executable found!”

本文提供了解决使用Java与OpenOffice连接时遇到的‘noofficeexecutablefound!’错误的方法,通过下载并配置bootstrapconnector.jar文件,实现与OpenOffice的正常连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public static void main(String[] args) {
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!
at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:243)
at syntax.main(syntax.java:38)

if you’re encountering “no office executable found!” follow these steps:

1. Download the file “bootstrapconnector.jar” attached to this post and save it.
2. Put the JAR file “bootstrapconnector.jar” for example in the same folder, where you put “juh.jar”, and add it to your CLASSPATH or add it in your IDE to the libraries for source code compiling (for example open in NetBeans the project properties and select there “Libraries” > tab “Compile” > press “Add JAR/Folder” > locate the “bootstrapconnector.jar” and press “Open”).
3. Determine the folder of your OpenOffice.org executable “soffice.exe” (on Windows systems) or “soffice” (on *nix systems). On Windows it might be something like “c:\program files\OpenOffice.org 2.3\program\”, and on *nix for example something like “/opt/openoffice.org2.3/program” or “/usr/lib/openoffice.org/program”.
4. Edit your Java source code file, that tries to get the connection by calling “Bootstrap.bootstrap()”. This is mostly done with a Java source code line looking like this:

Code: Select all Expand viewCollapse view
XComponentContext xContext = Bootstrap.bootstrap();

Perform the following steps in this Java source file:
1. Add the following line to your import statements:

Code: Select all Expand viewCollapse view
import ooo.connector.BootstrapSocketConnector;

2. Add a line above “Bootstrap.bootstrap()” to assign the name of the folder of your OpenOffice.org executable to a String variable:

Code: Select all Expand viewCollapse view
String oooExeFolder = “C:/Program Files/OpenOffice.org 2.3/program/”;

3. Change the call of “Bootstrap.bootstrap()” to “BootstrapSocketConnector.bootstrap(oooExeFolder)”:

Code: Select all Expand viewCollapse view
XComponentContext xContext = BootstrapSocketConnector.bootstrap(oooExeFolder);

4. Save and compile the edited file and see if “no office executable found!” has really vanished.
5. If you want to learn more about what you can do with “bootstrapconnector.jar”, stay tuned. (To be continued…)

bootstrapconnector.jar download linkers as follows:

http://user.services.openoffice.org/en/forum/download/file.php?id=836&sid=12df5c8cdc4d853aa8a6fc87071f922f


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值