Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

OpenOffice on the NetBeans Platform on Ubuntu

DZone's Guide to

OpenOffice on the NetBeans Platform on Ubuntu

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

Here's where I am with my OpenOffice integration on the NetBeans Platform:

OpenOffice opens in a TopComponent and I've copied a bunch of code into the document. Clearly, that's what one would hope to have as a result of this integration. Problems that remain are that the document isn't editable, the heavyweight/lightweight thing, and when I close the window OpenOffice crashes.

But those are all details at this point. How to get to the above state? Create a NetBeans Platform application, with a module that has this content:

Next, in the Installer, add this code:

public class Installer extends ModuleInstall {

    @Override
    public void restored() {
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
            @Override
            public void run() {
                try {
                    OOoBean oBean = new OOoBean();
                    TopComponent tc = WindowManager.getDefault().findTopComponent("OooTopComponent");
                    tc.add(oBean);
                    oBean.loadFromURL("private:factory/swriter", null);
                    Thread.sleep(3000);
                    oBean.aquireSystemWindow();
                } catch (InterruptedException ex) {
                    Exceptions.printStackTrace(ex);
                } catch (SystemWindowException ex) {
                    Exceptions.printStackTrace(ex);
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                } catch (IllegalArgumentException ex) {
                    Exceptions.printStackTrace(ex);
                } catch (CloseVetoException ex) {
                    Exceptions.printStackTrace(ex);
                } catch (NoConnectionException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        });
    }

}
 

The Thread.sleep is to provide some time while OpenOffice starts up and is embedded, but maybe that time isn't necessary after all.

The most important thing to get this to work is to include the appropriate JARs and native libs:

 

The bootstrapconnector.jar comes from here and is required for finding the OpenOffice installation, though that isn't necessary in this sample. (It is used in a different scenario where I wanted to simply open OpenOffice, not embed it. I don't think OfficeBean requires the above.) On the other hand, libjpipe.so is crucial (get it from /usr/lib/ure/lib).

More experiments with this scenario coming soon. Hope someone can help with the problems pointed out above, re editable mode of the OpenOffice document, especially.

 

 

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}