April 27
by hol.sten on Sun Feb 10, 2008 4:10 pm
Introduction
This is a short How-To for quickly solving the regularly occurring error "no office executable found!". You can read a huge number of threads in various OpenOffice.org forums dealing with this problem. This error is caused by using the Bootstrap Connection Mechanism (introduced with OOo 2.x) in conjunction with moving or copying "juh.jar" (OOo's "Java UNO Helper" JAR file containing the class file "Bootstrap.class") from the subfolder "program\classes" of the OOo installation folder (which is for example on Windows "c:\program files\OpenOffice.org 2.3") to another folder (mostly a subfolder, which is directly accessible from a web container or web server like for example Tomcat).
How-to
So, if you're encountering "no office executable found!" follow these steps:
- Download the file "bootstrapconnector.jar" attached to this post and save it.
- 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").
- 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".
- 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 VIEW
XComponentContext xContext = Bootstrap.bootstrap();
Perform the following steps in this Java source file: - Add the following line to your import statements:
- CODE: SELECT ALL EXPAND VIEW
import ooo.connector.BootstrapSocketConnector;
- 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 VIEW
String oooExeFolder = "C:/Program Files/OpenOffice.org 2.3/program/";
- Change the call of "Bootstrap.bootstrap()" to "BootstrapSocketConnector.bootstrap(oooExeFolder)":
- CODE: SELECT ALL EXPAND VIEW
XComponentContext xContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
- Save and compile the edited file and see if "no office executable found!" has really vanished.
If you want to learn more about what you can do with "bootstrapconnector.jar", stay tuned. (To be continued...)Credits
Most of the source code in the attached JAR file has been taken from the Java class "Bootstrap.java" (Revision: 1.15) from the UDK projekt (Uno Software Development Kit) from OpenOffice.org (
http://udk.openoffice.org/). The source code is available for example through a browser based online version control access at
http://udk.openoffice.org/source/browse/udk/. The Java class "Bootstrap.java" is there available at
http://udk.openoffice.org/source/browse ... iew=markupThe idea to develop the BootstrapConnector, BootstrapSocketConnector and BootstrapPipeConnector comes from the blog "Getting started with the OpenOffice.org API part III : starting OpenOffice.org with jars not in the OOo install dir by Wouter van Reeven" (
http://technology.amis.nl/blog/?p=1284) and from various posts in the "(Unofficial) OpenOffice.org Forum" at
http://www.oooforum.org/ and this forum complaining about "no office executable found!".
Jar file (attached as ZIP file)
- ATTACHMENTS
-
bootstrapconnector.jar - The JAR file "bootstrapconnector.jar" contains several class and source files and a Java example using the BootstrapSocketConnector class.
- (15.95 KiB) Downloaded 1504 times
Last edited by hol.sten on Thu Apr 10, 2008 9:50 pm, edited 2 times in total.
April 24
Posted by: chee khen liew on April 05, 2009 in response to Message #193333
I managed to converted RTF/Doc files to PDF using OpenOffice, here my steps:
1) Installed OpenOffice 2.4 (I failed to compile in OpenOffice 3 coz they have changed the jar files folder structure)
2) You need these 3 files in your classpath:
unoil.jar, juh.jar, ridl.jar
You will find them in: "C:\Program Files\OpenOffice.org 2.4\program\classes"
(Note: Do NOT copy out these 3 files, you must linked them in the original location, or else you will get runtime error for not able to find the executable)
----------------------------------
try {
// get the remote office component context
com.sun.star.uno.XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
// get the remote office service manager
com.sun.star.lang.XMultiComponentFactory xMCF =
xContext.getServiceManager();
Object oDesktop = xMCF.createInstanceWithContext(
"com.sun.star.frame.Desktop", xContext);
com.sun.star.frame.XComponentLoader xCompLoader =
(com.sun.star.frame.XComponentLoader)
UnoRuntime.queryInterface(
com.sun.star.frame.XComponentLoader.class, oDesktop);
java.io.File file = new java.io.File(sourceFile);
StringBuffer sLoadUrl = new StringBuffer("file:///");
sLoadUrl.append(file.getCanonicalPath().replace('\\', '/'));
file = new java.io.File(outputFile);
StringBuffer sSaveUrl = new StringBuffer("file:///");
sSaveUrl.append(file.getCanonicalPath().replace('\\', '/'));
com.sun.star.beans.PropertyValue[] propertyValue =
new com.sun.star.beans.PropertyValue[1];
propertyValue[0] = new com.sun.star.beans.PropertyValue();
propertyValue[0].Name = "Hidden";
propertyValue[0].Value = new Boolean(true);
Object oDocToStore = xCompLoader.loadComponentFromURL(
sLoadUrl.toString(), "_blank", 0, propertyValue );
com.sun.star.frame.XStorable xStorable =
(com.sun.star.frame.XStorable)UnoRuntime.queryInterface(
com.sun.star.frame.XStorable.class, oDocToStore );
propertyValue = new com.sun.star.beans.PropertyValue[ 2 ];
propertyValue[0] = new com.sun.star.beans.PropertyValue();
propertyValue[0].Name = "Overwrite";
propertyValue[0].Value = new Boolean(true);
propertyValue[1] = new com.sun.star.beans.PropertyValue();
propertyValue[1].Name = "FilterName";
propertyValue[1].Value = "writer_pdf_Export";
xStorable.storeToURL( sSaveUrl.toString(), propertyValue );
System.out.println("\nDocument \"" + sLoadUrl + "\" saved under \"" +
sSaveUrl + "\"\n");
com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
oDocToStore );
if (xCloseable != null ) {
xCloseable.close(false);
} else
{
com.sun.star.lang.XComponent xComp = (com.sun.star.lang.XComponent)
UnoRuntime.queryInterface(
com.sun.star.lang.XComponent.class, oDocToStore );
xComp.dispose();
}
System.out.println("document closed!");
System.exit(0);
----------------------------------
Hope that helps, enjoy!