Connect to OpenOffice with Java using SDK

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
laara_12
Posts: 15
Joined: Mon Sep 04, 2023 7:03 am

Connect to OpenOffice with Java using SDK

Post by laara_12 »

Hi team,

I'm trying to connect to OpenOffice through JAVA code. I want to load a document present at the path, using OpenOffice sdk. I'm Using XComponentContext xContext = Bootstrap.bootstrap(), I am trying to get the remote office component context of OpenOffice through Java. But it raises the exception "no office executable". I've set the SDK path as shown in the image, and added the classpath as well, as mentioned in https://stackoverflow.com/questions/141 ... 1#59337721. and I'm still getting the error. I have attached my JAVA code, openOffice SDK path, and Java JDK path.

Please help me in resolving this error.


SDK PATH:-
---------------------
laara_12@laara_12-MacBook-Pro OpenOffice_SDK % ./setsdkenv_unix
In file included from <stdin>:1:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cstring:60:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string.h:60:15: fatal error: 'string.h' file not found
#include_next <string.h>
^~~~~~~~~~
1 error generated.

************************************************************************
*
* SDK environment is prepared for MacOSX
*
* SDK = /Users/laara_12/Desktop/OpenOffice_SDK
* Office = /Applications/OpenOffice.app
* Make = /usr/bin
* Zip = /usr/bin
* cat = /bin
* sed = /usr/bin
* C++ Compiler = /Library/Developer/CommandLineTools/usr/bin
* Java =
* Boost =
* SDK Output directory = /Users/laara_12/OpenOffice_SDK
* Auto deployment = YES
*
* PATH = /Library/Developer/CommandLineTools/usr/bin:/bin:/usr/bin:/usr/bin:/usr/bin:/Users/laara_12/Desktop/OpenOffice_SDK/bin:/Users/laara_12/OpenOffice_SDK/MACOSXexample.out/bin:/Applications/OpenOffice.app/Contents/MacOS:.:/Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home/bin:/opt/homebrew/bin:/Library/Developer/CommandLineTools/usr/bin:/bin:/usr/bin:/usr/bin:/usr/bin:/Users/laara_12/Desktop/OpenOffice_SDK/bin:/Users/laara_12/OpenOffice_SDK/MACOSXexample.out/bin:/Applications/OpenOffice.app/Contents/MacOS:.:/Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home/bin:/opt/homebrew/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Users/Applications/OpenOffice.app/Contents/program:/usr/local/bin:/usr/local/bin
* DYLD_LIBRARY_PATH = /usr/lib:/Users/laara_12/OpenOffice_SDK/macosx/lib:/Users/laara_12/OpenOffice_SDK/MACOSXexample.out/lib:/Applications/OpenOffice.app/Contents/MacOS:.:
*
************************************************************************

JAVA CODE:
------
public class LodDocumet {
public static void main(String[] args) throws BootstrapException {
try {
XComponentContext xContext = Bootstrap.bootstrap();

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

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

// Query for the XComponentLoader interface
XComponentLoader xCompLoader = (XComponentLoader) UnoRuntime.queryInterface(
XComponentLoader.class, oDesktop);

String documentURL = "file:///Users/laara_12/Desktop/Cosmos/OpenOffice/OpenOfficeCode/src/main/java/org/example/laara_12.odt";

PropertyValue[] loadProps = new PropertyValue[0];

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

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

Thanks
OpenOffice 4.1.14 on X86_64 Ubuntu
Post Reply