Developing Scripts in NetBeans
This document describes how to set up NetBeans for Office Scripting
and how to write a simple script using NetBeans. You can download
the NetBeans IDE from the
NetBeans download page.
Contents:
Pre-requisites
- The Office Scripting module works with NetBeans 3.4
- You should have installed the Office Scripting module during the
installation process for the Scripting Framework. If you have not installed
it, see the Installation Guide for
instructions on how to install.
- On Linux, you will need to ensure that your DISPLAY environment
variable is set to <your hostname>:0 in the shell from which you
start NetBeans to work around a problem with Java GUIs in Office.
- Create a directory somewhere on your machine in which you will develop
your scripts.
Now start NetBeans and mount the directory you created using the
File/Mount Filesystem menu option. You also need to mount all of the jar
files in the <Office installation>/program/classes directory in
order to access the Office API from your scripts.
Top
Creating a Parcel Recipe
Office scripts are delivered in Script Parcels. Like Office 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 Office 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 Office 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 Office 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 Office Document
or to an Office 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 Office documents within NetBeans
using drag and drop or cut and paste.
Top
Actions available for Office Documents
Office Documents are also recognised by NetBeans. Any parcels contained
in the document will be displayed as nodes of the Office 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.
Office documents support the standard Delete, Cut and Copy actions and
the following custom actions:
- Open: This will open the document in Office using the path
in the Office Settings property to find the Office installation.
If the path to Office 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 Office scripts in NetBeans
- Follow the instructions at
Debugging Java components in NetBeans/Forte for Java
to set up your Office installation to allow debugging of the JVM.
- Start OpenOffice and run one of your Java scripts. This will
make sure the JVM is running.
- Attach to Office 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 Office.
Note: As the BeanShell scripting language does not support debugging
it is not possible to debug BeanShell Office 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: Tue Mar 12 11:40:28 GMT 2003