četrtek, 13. julij 2006

Integrating OpenOffice SDK into NetBeans

If you want to develop applications that use OpenOffice with NetBeans do the following:
- I have OpenOffice installed in /usr/lib/openoffice (OOO_HOME)
- create a project (OpenOffice for example)
- create a class library (OpenOfficeLib for example):
- in Classpath put:
  • OOO_HOME/program/classes/juh.jar
  • OOO_HOME/program/classes/jurt.jar
  • OOO_HOME/program/classes/ridl.jar
  • OOO_HOME/program/classes/unoil.jad
  • OOO_HOME/program/classes/officebean.jar
  • OOO_HOME/sdk/classes
- right click OpenOffice project and choose Properties:
- Libraries: add OpenOfficeLib library on Compile tab
- Run:
  • Main Class: com.sun.star.lib.loader.Loader
  • Arguments : YOUR_MAIN_CLASS
  • VM Options: -Djava.library.path="OOO_HOME/program" -Dcom.sun.star.lib.loader.unopath="OOO_HOME/program"
- put the following code into your class:
XComponentContext xLocalContext = Bootstrap.bootstrap();
XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
Object desktop = xLocalServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xLocalContext);
XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop);
PropertyValue[] pPropValues = new PropertyValue[0];
XComponent xWriterComponent = xComponentLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, pPropValues);

- run your project with F6 and voila. You get OpenOffice Writer opened. :)

Then use the OpenOffice Developer's Guide to create something useful. :)
Objavite komentar