[Libreoffice] java-application and libreoffice
Jochen georges
gnugeo at gnugeo.de
Fri Mar 18 14:04:01 PDT 2011
Hello Developers,
I hope this is the right place to ask.
I've tried to write a simple Java-Application that writes an odt-file.
I can compile it, but I can't execute it:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
com.sun.star.lib.connections.pipe.PipeConnection.createJNI(Ljava/lang/String;)I
at
com.sun.star.lib.connections.pipe.PipeConnection.createJNI(Native Method)
at
com.sun.star.lib.connections.pipe.PipeConnection.<init>(PipeConnection.java:128)
at
com.sun.star.lib.connections.pipe.pipeConnector.connect(pipeConnector.java:137)
at com.sun.star.comp.connections.Connector.connect(Connector.java:141)
at
com.sun.star.comp.urlresolver.UrlResolver$_UrlResolver.resolve(UrlResolver.java:123)
at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:285)
at TestOOAPI.<init>(TestOOAPI.java:20)
at TestOOAPI.main(TestOOAPI.java:15)
Can you give me a hint?
Or is there somewhere a step by step howto for dummies?
Thanks in advance
Beste Grüße
Jochen
################################################################################################
TestOOAPI.java
################################################################################################
//In Anlehnung an:
http://openofficejava.blogspot.com/2009/05/openofficeorg-api.html
import com.sun.star.beans.PropertyValue;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.comp.helper.BootstrapException;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.text.XText;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public class TestOOAPI {
public static void main(String[] args) {
new TestOOAPI();
}
public TestOOAPI(){
try {
// Get the remote office component context
XComponentContext xContext = Bootstrap.bootstrap();
// Get the remote office service manager
XMultiComponentFactory xMCF = xContext.getServiceManager();
try{
// Get the root frame (i.e. desktop) of openoffice
framework.
Object oDesktop =
xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
// Desktop has 3 interfaces. The XComponentLoader
interface provides ability to load components.
XComponentLoader xCLoader =
( XComponentLoader )
UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
// Create a document
XComponent document =
xCLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0,
new PropertyValue[0]);
// Get the textdocument
XTextDocument aTextDocument =
( XTextDocument
)UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, document);
// Get its text
XText xText = aTextDocument.getText();
// Adding text to document
xText.insertString(xText.getEnd(), "My First OpenOffice
Document", false);
}catch(Exception ex){ex.printStackTrace();}
} catch (BootstrapException e) {e.printStackTrace();}
}
}
################################################################################################
compile-run.sh
################################################################################################
#!/bin/sh
JAVAC=javac
JAVA=java
export
CLASSPATH=$CLASSPATH:.:/usr/share/java/openoffice/juh.jar:/usr/share/java/openoffice/jurt.jar:/usr/share/java/openoffice/ridl.jar:/usr/share/java/openoffice/unoil.jar:/usr/lib/openoffice/program/soffice
if [ $1 -eq 0 ]; then
echo "compile"
$JAVAC TestOOAPI.java
elif [ $1 -eq 1 ]; then
echo "run"
#test 1:
----------------------------------------------------------------------
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/openoffice/program/
$JAVA TestOOAPI
#test 2:
----------------------------------------------------------------------
#$JAVA -Djava.library.path=/usr/lib/openoffice/program/ TestOOAPI
else
echo ""
echo "give me a 0 or 1 please"
fi
################################################################################################
diverse pfade
################################################################################################
ls /usr/share/java/openoffice/
agenda.jar com commonwizards.jar fax.jar form.jar java_uno.jar
JREProperties.class js.jar juh.jar juh_src.zip jurt.jar jurt_src.zip
letter.jar lucene-analyzers-2.3.jar lucene-core-2.3.jar
LuceneHelpWrapper.jar query.jar report.jar ridl.jar ridl_src.zip
sandbox.jar saxon9.jar ScriptFramework.jar
ScriptProviderForBeanShell.jar ScriptProviderForJava.jar
ScriptProviderForJavaScript.jar table.jar unoil.jar unoloader.jar
unoloader_src.zip web.jar win XMergeBridge.jar xmerge.jar XSLTFilter.jar
XSLTValidate.jar
which soffice
/usr/bin/soffice
ls -l /usr/bin/soffice
lrwxrwxrwx 1 root root 33 2011-02-03 14:17 /usr/bin/soffice ->
../lib/openoffice/program/soffice
More information about the LibreOffice
mailing list