How to create a new URE based application ? The documentation is quite hard to find, but the main important thing is: create a UNO component implementing the com.sun.star.lang.XMain interface. This one will contain a method run(). I'll explain how to create a "Hello URE World" application.

The project will be organized in the following way:

  • idl diretory containing the application UNOIDL specifications
  • source directory containing the implementation of the UNOIDL types
  • program directory which will contain the application registries and libraries
  • MANIFEST.MF file which will describe the registration class of the component
  • Makefile file to make the build much easier
  • unotest file to launch the newly created application

UNOIDL file definition

The file idl/org/unotest/Main.idl will describe a simple service org.unotest.Main exporting the XMain interface this gives the following code:

module org { module unotest {
    service Main: com::sun::star::lang::XMain {
        create ();
    }
}; };

Note that this service is a new style one: defining constructors and exporting a single interface.

Java implementation

Now just create a org.unotest.comp.MyMain Java class in the source/org/unotest/comp/MyMain.java file. This class will implement the following three methods:

public int run (String[] arguments) {
    // Printing Hello URE World ;) and exit
    System.out.println("Hello URE World ;)");
    return 0;
}

__getServiceFactory(...) and __writeRegistryServiceInfo(...) are used for the component registration. They implementation is fully described in the chapters 4.5.3 and 4.5.4 of the OpenOffice.org Developer Guide

Generation of the component

The component generation works like the OpenOffice.org components generation, however there are some tricky things to know:

  • use the URE regmerge and regcomp tools. Otherwise you will get some Loader exceptions when trying to use regcomp on your component.
  • do not put your class files directly in your current directory: this is a new issue that will be corrected. If you do not respect this advice, the regcomp tool will use the class files in your current directory before the one in your jar file.

In our unotest case, the build instructions are written in the Makefile. It should use the following tools:

  1. idlc -Ourd -I\$(SDK_HOME}/idl idl/org/unotest/Main.idl
  2. \$(URE_HOME)/bin/regmerge program/types.rdb UCR urd/Main.urd
  3. javamaker -Torg.unotest.Main -BUCR program/types.rdbb -X\$(URE_HOME)/share/misc/services.rdb -X\$(URE_HOME)/share/misc/types.rdb
  4. javac -d . -cp \$(CLASSPATH) source/org/unotest/comp/MyMain.java
  5. jar cfm program/unotest.uno.jar MANIFEST.MF org/unotest/compMyMain.class org/unotest/Main.class
  6. rm -Rf org
  7. \$(URE_HOME)/bin/regcomp -register -br \$(URE_HOME)/share/misc/types.rdb -br \$(URE_HOME)/share/misc/services.rdb -r program/services.rdb -c file://\$(PWD)/program/unotest.uno.jar -classpath \$(CLASSPATH)

What will these commands do ?

  1. Compile your UNOIDL specification to create the urd/Main.urd registry
  2. Merge the generated urd file in the program/types.rdb registry
  3. Create the org/unotest/Main.class file
  4. Compile your java implementation of the service
  5. Create the jar file of the component
  6. Delete the unused class files to avoid problems with regcomp
  7. Register the component in the URE

Launching the application

In the unotest file, you just have to put a call to the uno tool contained in the URE:

   $URE_HOME/bin/uno -c org.unotest.comp.MyMain   
                    -l file://`pwd`/program/unotest.uno.jar   
                    -ro program/services.rdb   
                    -ro program/types.rdb   
                    -ro $URE_HOME/share/misc/services.rdb   
                    -ro $URE_HOME/share/misc/types.rdb

Thus when launching the unotest file, you will launch the URE with you org.unotest.comp.MyMain as the main class to load at the beginning. This will print you the expected "Hello URE World ;)"

The next step is to do the same with a C++ component... but I'm still working on it.