solution “no office executable found!”

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


你可能感兴趣的:(solution “no office executable found!”)