Every developer needs a way to debug its applications. It goes the same way for OpenOffice.org Java extensions. At the OOoCon 2008 in Barcelona, Steffen Grund explained me how he integrated OOo Java extensions debugging in the Netbeans plugin. Even if it was very interesting, I only had time to do it with Eclipse and here is how to do it.
Configuring OpenOffice.org
First, you need to add parameters to the JVM started by OpenOffice.org. The parameters are:
-Xdebug
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
To change them, open the OOo options dialog and then the Java
configuration item.
Click on the Parameters button and add the parameters.
In order to apply the parameters, you need to restart OOo (the quickstarter too). These parameters will make OpenOffice.org JVM listen on the 8000 port of the local machine.
Starting the debug mode from Eclipse
Open the Run > Open Debug Dialog menu.
Create a new Remote Java Application with the following parameters:
- Connection type: Standard (Socket Attach)
- Host: localhost
- Port: 8000
- Sources: your project directory should be selected
Then run the extension from OpenOffice.org (using a Basic macro or anything else) and then start the newly created debug configuration. It may be possible that the connection can't be fetched at the first time because OOo starts the JVM only when it's needed. After a first run, the started JVM won't be stopped and the port will still be opened.
Tips & Tricks
- Don't forget to add the breakpoints in your code before exporting it, otherwise they won't be taken into account at the runtime.
- You will need to close OpenOffice.org (the quickstarter too) when exporting the package from Eclipse or you will get an error telling you that the 8000 port is already in use.
- You can change the port to something else than 8000 of course, change it in the OOo JVM parameters and in the Eclipse Debug configuration