javasdkopenoffice.orguno

Error While Loading Document using OpenOffice SDK in JAVA


I'm trying to Load a document using OpenOffice SDK in JAVA. I'm Using XComponentContext xContext = Bootstrap.bootstrap(), and trying to get the remote office component context of OpenOffice through Java. But it raises the exception no office executable.

I have attached my JAVA code, openOffice SDK path, and Java JDK path. The version of OpenOffice is 4.1.14, machine is MacOS x86_64 and Java version 8

Path of OpenOffice sdk in my local: Path of OpenOffice sdk in my local

Error message: no office executable found Error message: no office executable found

Location of OpenOffice SDK - /Users/madhup/Desktop/OpenOffice_SDK

Java JDK Path - /Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home/bin/javac

zshrc profile: zshrc profile

Java code:

import com.sun.star.beans.PropertyValue;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.uno.UnoRuntime;

import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.BootstrapException;
public class LoadDocument {
    public static void main(String[] args) throws BootstrapException {
        try {
            XComponentContext  xContext = Bootstrap.bootstrap();

            com.sun.star.lang.XMultiComponentFactory xMCF = xContext.getServiceManager();

            Object oDesktop = xMCF.createInstanceWithContext(
                    "com.sun.star.frame.Desktop", xContext);

            XComponentLoader xCompLoader = (XComponentLoader) UnoRuntime.queryInterface(
                    XComponentLoader.class, oDesktop);

            String documentURL = "file:///Users/path_to_file/hello.odt";

            PropertyValue[] loadProps = new PropertyValue[0];

            XComponent xComponent = xCompLoader.loadComponentFromURL(
                    documentURL, "_blank", 0, loadProps);

            if (xComponent != null) {
zshrc profile paths                System.out.println("Document loaded successfully.");
                xComponent.dispose();
            } else {
                System.out.println("Failed to load the document.");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Pom file:

<dependencies>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>unoil</artifactId>
            <version>4.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>juh</artifactId>
            <version>4.1.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>jurt</artifactId>
            <version>4.1.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>ridl</artifactId>
            <version>4.1.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>officebean</artifactId>
            <version>4.1.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.github.jeremysolarz</groupId>
            <artifactId>bootstrap-connector</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>

I've already explored, set the SDK path, and added the classpath as mentioned in No office executable found exception while connecting to OpenOffice through Java and still getting the error.

Please help in resolving this problem.


Solution

  • Adding soffice path

    Add the path of the soffice in your project dependency, and it will work. In my case it was /opt/Libreoffice7.6/program/