Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

JSDT/Debug/Rhino/Using Rhino Console

< JSDT‎ | Debug‎ | Rhino
JSDT Debug
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse SourceProject Set File

Overview

The Rhino console can be a powerful way to work with JavaScript within Rhino. Simply put, the Rhino console allows you to interact with the Rhino interpreter using System.in and System.out. You can also debug these interactions with a Remote JavaScript launch configuration.

The details of the console, and what it supports can be found here.

Starting the Console

There are many ways to start the console and we will discuss two of them here:

  1. start the console from an Eclipse workspace
  2. start the console from a system terminal

From Eclipse

To start the console from within an Eclipse workspace, we first have to get the source for the org.eclipse.wst.jsdt.debug.rhino.debugger project. This project can be obtained by simply importing the team project set for the JSDT debugger found here.

Once the source has been added to your workspace and has been built, we have to create a new Java Application launch configuration for the org.eclipse.wst.jsdt.debug.rhino.debugger.shell.DebugShell class. When creating the new launch configuration, there are some options that can be used in the Program Arguments section on the Arguments tab.

The following table summarizes the supported options for launching the Rhino console.

Option What it does Example
-port Allows you to specify the port that the console should communicate on -port 5000
-suspend Allows to specify if the console should start and then wait until a debugger connects before continuing -suspend true OR -suspend y
-trace Allows you to specify if the console should output status messages -trace true


At this point you should have a new Java Application launch configuration that looks like the following (assuming you added the -port and -suspend options):

Regardless of your use of the -suspend option, at this point the console can be connected to by a remote debugger.

From the Terminal

To run the console from a system terminal requires a lot more typing, but the net result is the same. I am going to assume that you already have Java installed and configured on your machine.

The key to running this from the terminal is that you have the built jars for the following bundles:

  1. org.eclipse.wst.jsdt.debug.transport
  2. org.eclipse.wst.jsdt.debug.rhino.debugger
  3. org.mozilla.javascript

The aforementioned bundles will be included on the classpath using the -cp option like the following:

-cp org.mozilla.javascript.jar:org.eclipse.wst.jsdt.debug.transport.jar:org.eclipse.wst.jsdt.debug.rhino.debugger.jar

An important note here is the use of a colon to delimit classpath entries. The colon is used on Linux-based system and the semicolon is used on Windows.

The main class that we want to run is:

org.eclipse.wst.jsdt.debug.rhino.debugger.shell.DebugShell

The options that can be specified are:

Option What it does Example
-port Allows you to specify the port that the console should communicate on -port 5000
-suspend Allows to specify if the console should start and then wait until a debugger connects before continuing -suspend true OR -suspend y
-trace Allows you to specify if the console should output status messages -trace true

The whole command would then look like:

terminal$ java -cp org.mozilla.javascript.jar:org.eclipse.wst.jsdt.debug.transport.jar:org.eclipse.wst.jsdt.debug.rhino.debugger.jar 
               org.eclipse.wst.jsdt.debug.rhino.debugger.shell.DebugShell -port 9000 -suspend y

Attaching the Debugger

After following the steps outlined in Starting the Console you should have the Rhino console up and running and see something like the following, either in your terminal or the Eclipse console:

Rhino debugger
Start at time: November 19, 2010 11:21:51 CST AM
Listening to socket on port: 9000
Rhino 1.7 release 2 2009 03 22
js> 

The next thing we want to do is attach the remote debugger to be able to debug whatever we do in the console.

First thing we have to do is create a new Remote JavaScript launch configuration. This can only be done in launch configuration dialog opened in debug mode.

Once a new configuration is created we have to configure it to use the Mozilla Rhino - Attaching Connector and set the port and host to be the same as what you used to start the console. Mainly you only have to worry about setting the port, as the console currently does not support being started on a remote host.

Once configured your configuration should look like the following:


The last step is to launch the configuration. Once launched you should see a new Rhino debug target in the Debug View and the usual commands enabled and ready to use.

Console Commands

Very good information about all of the supported commands and their effects can be found here.

Back to the top