RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Dynamic Scripting Lands in Europa: A Profile of Eclipse Monkey

Bring the power of JavaScript into your Eclipse workspace and learn how to make the most of it.

he recent Eclipse Europa release is the culmination of coordinated efforts between a number of Eclipse subprojects. Its major components, such as the Java Development Tools (JDT) and Web Tools Platform (WTP), garner a majority of the interest, but many other Europa projects are worth a try. This article introduces just such an under-the-radar project: Eclipse Monkey, a tool for creating, using, and sharing interpreted scripts (in the JavaScript programming language) that interact with the Eclipse platform.

Don't confuse Eclipse Monkey with the Eclipse Dynamic Languages Toolkit (DLTK) project. The former integrates user-created JavaScript that enrich platform capabilities; the latter extends the set of programming languages supported by the platform with new editors, debuggers, and other development tools.

Eclipse Monkey relies on the Mozilla Rhino JavaScript engine to evaluate scripts. This is the same engine that powers the Firefox web browser and ships with Java SE 6 as an implementation of the JSR-223 specifications for scripting engines (Rhino permits interoperation between scripts and the Java environment in which the scripts run.). So developers can leverage the JavaScript skills they gained from writing scripts either for the web or within Java SE 6 applications to create Monkey scripts.

Get Started
The first step in using Eclipse Monkey is installation. This is a straightforward process:

  1. Open the Update Manger.
  2. Search for new features to install on the Europa Discovery Site.
  3. Choose the Monkey project.

The Update Manager also installs the Mozilla Rhino JavaScript engine, on which Eclipse Monkey depends.

After the installation finishes, you are ready to test your first script:

  1. Create a new project.
  2. Create a folder named scripts.
  3. Create the following "Hello World" script inside the scripts folder and call it test.js:
     * Menu: Simple > Hello world
    function main() {
    	"Hello world!");	

On the menu bar, a new entry appears inside the Scripts menu. It points to your just created script. When you click it, a dialogs pops up with the classic hello world message.

Behind the Scenes
The "Hello World" script uses the Packages prefix to access the MessageDialog Java class available within the Eclipse platform and to invoke the static openInformation() method on it. This is the standard method that Eclipse components use to open a message dialog box. The Packages object is a Rhino-specific feature (as described in its official documentation) that provides the bridging capabilities between Java and JavaScript.

JavaScript is the only language that Eclipse Monkey supports out of the box, but you can contribute additional ones by using the org.eclipse.eclipsemonkey.language extension point and following the standard practice for creating additional components for the Eclipse platform. This extension point describes the interfaces to implement for integrating an additional language with Monkey.

However, keep in mind that Eclipse Monkey is not JSR-223 aware; you cannot plug in support for other scripting languages in the same way you do in a standard Java application based on Java SE 6. That is, you cannot provide new scripting engines by using the interfaces exposed in the javax.script packages. If you are interested in this kind of scripting support for Eclipse (e.g., plug-ins and extensions in interpreted languages such as Ruby), refer to my previous DevX article on the subject.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date