Developing Scripts in NetBeans
This document describes how to set up NetBeans for OpenOffice.org Scripting
and how to write a simple script using NetBeans. You can download
the NetBeans IDE from the
NetBeans download page.
Contents:
Pre-requisites
- Install the OpenOffice.org Scripting module
To install this module, shutdown NetBeans and copy the office.jar file to
your <NetBeans installation>/modules directory.
- Create a directory somewhere on your machine in which you will develop
your scripts.
- Note: The OpenOffice.org Scripting module has been tested with NetBeans 3.4
Now start NetBeans and mount the directory you created using the
File/Mount Filesystem menu option. You also need to mount the following
of the jar files in the <OpenOffice.org installation>/program/classes directory
in order to access the OpenOffice.org API from your scripts:
unoil.jar, ridl.jar, sandbox.jar, jurt.jar, juh.jar
Top
Creating a Parcel Recipe
OpenOffice.org scripts are delivered in Script Parcels. Like OpenOffice.org documents they
are zip files. Script Parcels have the .sxp extension. Script Parcels are
generated from Parcel Recipes where all of the files that are necessary
to create the parcel are put together. To create a new Parcel Recipe:
- Right click on your mounted filesystem
- Select New/Office Scripting/Parcel Recipe
- In the New Wizard window that appears enter a name for your Parcel Recipe
- Select a language for your Parcel Recipe from the Initial Script
Language dropdown list.
- Click the Finish button to create your Parcel Recipe
This will create a new directory with the name you chose. In this directory
you will find a Contents directory where all of your files will
be placed. An empty stub file will have been placed in the
Contents directory and can be used as a starting point for your script.
Note: To add further empty stub scripts to your Parcel Recipe, right
click on the Contents directory and use the New/Office Scripting/Empty Script
menu item.
Top
Actions available for Parcel Recipe
If the user right clicks on the parcel directory they should be
able to use the following actions:
- Compile: Compiles all of the .java files in the Parcel Recipe
- Build: Compiles all of the .java files in the Parcel Recipe.
It then searches for valid OpenOffice.org scripts in the language you selected
in the Contents directory files and pops up a dialog
which allows you to select which Java methods or BeanShell scripts
you wish to export as OpenOffice.org scripts.
Once you have finish making your selections, it creates a
<Parcel Recipe Name>.sxp Script Parcel file in the Parcel
Recipe directory. You can configure what files are put into the
Script Parcel using the File Filter property. If you script includes any
jar files that need to be in the classpath when it is executed you should
add them to the Classpath property of your Parcel Recipe.
- Configure: This pops up the Configure dialog, which allows you
to select what OpenOffice.org scripts to export. Any changes you make in
this dialog will only appear in your Script Parcel after you run
Build again.
Top
Actions available for Script Parcels
Script Parcels supports only one action:
- Deploy: This will deploy the Script Parcel to an OpenOffice.org Document
or to an OpenOffice.org installation. If the Script Parcel already exists
in the target, you will be asked whether you want to overwrite.
Note: If you deploy a Script Parcel to an OpenOffice.org
installation you need to use the Tools/Scripting Add-on's/Refresh All Scripts
menu item for the new script to appear in the Assign Script dialog.
Note: You can also deploy to OpenOffice.org documents within NetBeans
using drag and drop or cut and paste.
Top
Actions available for OpenOffice.org Documents
OpenOffice.org Documents are also recognised by NetBeans. Any parcels contained
in the document will be displayed as nodes of the OpenOffice.org document. Deleting
one of these nodes will remove the Script Parcel from the document. You
should ensure that the document is not open in OpenOffice.org before deleting
any parcels it may contain.
OpenOffice.org documents support the standard Delete, Cut and Copy actions and
the following custom actions:
- Open: This will open the document in OpenOffice.org using the path
in the Office Settings property to find the OpenOffice.org installation.
If the path to OpenOffice.org is not valid, an error dialog will be popped
up informing the user that they need to set their Path to Office
Installation property. This setting can be changed by bringing
up the Tools/Options dialog and changing
IDE Configuration/Server and External Tool Settings/Office Settings
Top
Debugging Java OpenOffice.org scripts in NetBeans
- Follow the instructions at
Debugging Java components in NetBeans/Forte for Java
to set up your OpenOffice.org installation to allow debugging of the JVM.
- Start OpenOffice.org and run one of your Java scripts. This will
make sure the JVM is running.
- Attach to OpenOffice.org JVM using the NetBeans Debug/Start Session/Attach...
menu option.
- Load a script source in NetBeans and set up breakpoints using
Debug/New Breakpoint... menu option.
- Run the script in OpenOffice.org.
Note: As the BeanShell scripting language does not support debugging
it is not possible to debug BeanShell OpenOffice.org scripts from NetBeans. You
can however use the Interactive BeanShell scripting menu item under the Tools
menu in OpenOffice.org to test BeanShell code. Just enter any BeanShell code
and hit the Eval button to execute it.
Top
Troubleshooting
If you encounter problems when developing or deploying scripts in
NetBeans, one thing you can try is to move your NetBeans settings directory
(.netbeans on UNIX, netbeans in Windows - can be found in your home
directory) to another name and restart NetBeans.
The Choose What to Export as Scripts dialog only displays
methods which are defined within class files, it will not display
methods in class files which are within jar files in the Parcel Recipe.
If you include package directives in the Java source files of your
Parcel Recipe, you should ensure that the source files are in the appropriate
directories for your package directives. This is because the
default NetBeans compiler implementation does not use the -d switch to the
Java compiler. As a result class files do not get placed in the appropriate
directories and methods in these classes will not appear in the
Choose What to Export as Scripts dialog.
There are a couple of workarounds for this problem:
- Use the command line tools
- Set the Target flag in the Tools/Options window under
Building/Compiler Types/Internal Compilation
Top
Last Modified: Nov 19 2003