OpenOffice Simple UNO Client Application Project Type

From Apache OpenOffice Wiki
Jump to: navigation, search

Back to NetBeans Integration


The Client Application wizard creates a new J2SE project with API support. This means the library is added to the project to provide code completion and context sensitive help for the API. The generated main function contains some code to bootstrap an UNO environment and returns the remote context object of the default installation on the system. This works only if a default installation of was made and the soffice binary in the <office>/program directory is in the path (at least reachable over a symbolic link). There are some fallback strategies possible which are not further discussed here.
The project builds a customized jar file containing special UNO bootstrap classes from the SDK and special manifest entries to support the simple UNO bootstrap feature. The UNO bootstrap feature enables the application jar to run without any further environment preparation and has full access to the API to control and automate the process.

Project Wizard

The project wizard is quite simple to use. Choose

  • File -> New Project -> -> Client Application

and follow the wizard.

  • Step 1: Select the project type

Simple Client1.png

  • Step 2: Define the project, class name, an optional package and the project location

Simple Client2.png

Generated Code

The generated code looks like

 * Created on 10.06.2006 - 17:45:42
package org.test;
 * @author XXXXX
public class TestClient {
    /** Creates a new instance of TestClient */
    public TestClient() {
     * @param args the command line arguments
    public static void main(String[] args) {
        try {
            // get the remote office component context
            XComponentContext xContext = Bootstrap.bootstrap();
            if (xContext == null) {
                System.err.println("ERROR: Could not bootstrap default Office.");
        catch (java.lang.Exception e){
        finally {
            System.exit( 0 );

Line 29 contains the UNO bootstrap call which returns the remote office context object. The remote context is main entry point to work with the API. The code is quite simple and should only show the first step. The generated project is buildable, runnable and can be started or debugged directly from within NetBeans as a normal J2SE application.

Manifest Entries for the UNO Bootstrap Mechanism

The manifest needs some special entries to support the simple UNO bootstrap feature:


Name: com/sun/star/lib/loader/Loader.class
Application-Class: org.test.TestClient

where org.test.TestClient is the original main class.

Bundled UNO Bootstrap Glue Code

The following precompiled class files and the dll from the SDK are bundled with the client application jar.


The unowinreg.dll is included so that the client application can be platform independent. It is used to find the default installation on Windows.

See also

Personal tools