Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "JSDT/Debug/Rhino/Using Rhino Console"

< JSDT‎ | Debug‎ | Rhino
m (JSDT/Debug/Using Rhino Console moved to JSDT/Debug/Rhino/Using Rhino Console: This page belongs to the Rhino group and the page breadcrumb takes you up too many pages from the context)
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{JSDT-Debug}}
+
{{JSDT-Debug}}  
  
== Overview ==
+
== 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 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 [http://www.mozilla.org/rhino/shell.html here].
+
The details of the console, and what it supports can be found [http://www.mozilla.org/rhino/shell.html here].  
  
== Starting the Console ==
+
== Starting the Console ==
  
There are many ways to start the console and we will discuss two of them here:
+
There are many ways to start the console and we will discuss two of them here:  
# start the console from an Eclipse workspace
+
# start the console from a system terminal
+
  
=== From Eclipse ===
+
#start the console from an Eclipse workspace
 +
#start the console from a system terminal
  
To start the console from within an Eclipse workspace, we first have to get the source for the <code>org.eclipse.wst.jsdt.debug.rhino.debugger</code> project. This project can be obtained by simply importing the team project set for the JSDT debugger found [http://www.eclipse.org/webtools/jsdt/psf/jsdt-debug.psf here].
+
==== From Eclipse ====
  
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 <code>org.eclipse.wst.jsdt.debug.rhino.debugger.shell.DebugShell</code> class. When creating the new launch configuration, there are some options for the launch that we should mention.  
+
To start the console from within an Eclipse workspace, we first have to get the source for the <code>org.eclipse.wst.jsdt.debug.rhino.debugger</code> project. This project can be obtained by simply importing the team project set for the JSDT debugger found [http://www.eclipse.org/webtools/jsdt/psf/jsdt-debug.psf here].  
  
The following table summarizes the supported options for launching the Rhino console.
+
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 <code>org.eclipse.wst.jsdt.debug.rhino.debugger.shell.DebugShell</code> class. When creating the new launch configuration, there are some options that can be used in the Program Arguments section on the Arguments tab.
  
{| border="1" cellspacing="0" cellpadding="5" align="left"
+
The following table summarizes the supported options for launching the Rhino console.<br>
! Option
+
 
! What it does
+
{| border="1" cellspacing="0" cellpadding="5"
 +
|-
 +
! Option  
 +
! What it does  
 
! Example
 
! Example
|-
 
| -port
 
| Allows you to specify the port that the console should communicate on
 
| -port=5000
 
 
|-
 
|-
| -suspend
+
| -port
| Allows to specify if the console should start and then wait until a debugger connects before continuing
+
| Allows you to specify the port that the console should communicate on
| -suspend=true OR -suspend=y
+
| <code>-port 5000</code>
 
|-
 
|-
| -trace
+
| -suspend
| Allows you to specify if the console should output status messages
+
| Allows to specify if the console should start and then wait until a debugger connects before continuing
| -trace=true
+
| <code>-suspend true</code> OR <code>-suspend y</code>
 +
|-
 +
| -trace  
 +
| Allows you to specify if the console should output status messages  
 +
| <code>-trace true</code>
 
|}
 
|}
  
At this point you should have a new Java Application launch configuration that looks like the following (assuming you added the <code>-port</code> and <code>-suspend</code> options).
 
  
[[Image:Debugshell-main-config.png|frame|The Main tab of the new configuration]]
+
At this point you should have a new Java Application launch configuration that looks like the following (assuming you added the <code>-port</code> and <code>-suspend</code> options):
  
[[Image:Debugshell-arg-config.png|frame|The Arguments tab of the new configuration]]
+
<gallery widths="300px" heights="250px">
 +
Image:Debugshell-main-config.png|The Main tab of the new configuration
 +
Image:Debugshell-arg-config.png|The Arguments tab of the new configuration
 +
</gallery>
  
Regardless of your use of the <code>-suspend</code> option, at this point the console can be connected to by a remote debugger.  
+
Regardless of your use of the <code>-suspend</code> option, at this point the console can be connected to by a remote debugger.
  
=== From the Terminal ===
+
==== From the Terminal ====
  
=== Attaching the Debugger ===
+
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.
  
At this point you should have the Rhino console up and running and see something like the following, either in your terminal or the Eclipse console:
+
The key to running this from the terminal is that you have the built jars for the following bundles:
 +
# org.eclipse.wst.jsdt.debug.transport
 +
# org.eclipse.wst.jsdt.debug.rhino.debugger
 +
# org.mozilla.javascript
  
 +
The aforementioned bundles will be included on the <code>classpath</code> using the <code>-cp</code> option like the following:
 
<pre>
 
<pre>
Rhino debugger
+
-cp org.mozilla.javascript.jar:org.eclipse.wst.jsdt.debug.transport.jar:org.eclipse.wst.jsdt.debug.rhino.debugger.jar
Start at time: November 19, 2010 11:21:51 CST AM
+
Listening to socket onport: 9000
+
Started suspended - waiting for client resume...
+
 
</pre>
 
</pre>
 +
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:
 +
<pre>
 +
org.eclipse.wst.jsdt.debug.rhino.debugger.shell.DebugShell
 +
</pre>
 +
 +
The options that can be specified are:
 +
 +
{| border="1" cellspacing="0" cellpadding="5"
 +
|-
 +
! Option
 +
! What it does
 +
! Example
 +
|-
 +
| -port
 +
| Allows you to specify the port that the console should communicate on
 +
| <code>-port 5000</code>
 +
|-
 +
| -suspend
 +
| Allows to specify if the console should start and then wait until a debugger connects before continuing
 +
| <code>-suspend true</code> OR <code>-suspend y</code>
 +
|-
 +
| -trace
 +
| Allows you to specify if the console should output status messages
 +
| <code>-trace true</code>
 +
|}
 +
 +
The whole command would then look like:
 +
<pre>
 +
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
 +
</pre>
 +
 +
== Attaching the Debugger ==
 +
 +
After following the steps outlined in [[#Starting_the_Console|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:
 +
<pre>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>
 +
</pre>
 
The next thing we want to do is attach the remote debugger to be able to debug whatever we do in the console.
 
The next thing we want to do is attach the remote debugger to be able to debug whatever we do in the console.
  
== Console Commands ==
+
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 <code>debug</code> mode.
  
Very good information about all of the supported commands and their effects can be found [http://www.mozilla.org/rhino/shell.html here].
+
Once a new configuration is created we have to configure it to use the <code>Mozilla Rhino - Attaching Connector</code> 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.
  
== Examples ==
+
Once configured your configuration should look like the following:
 +
 
 +
<gallery widths="300px" heights="250px">
 +
Image:Debugrhino-config.png|The connect tab of a Remote JavaScript configuration
 +
</gallery>
 +
 
 +
 
 +
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.
 +
 
 +
<gallery widths="300px" heights="50px">
 +
Image:Debugview-rhino.png|Example Rhino launch in the Debug View
 +
</gallery>
 +
 
 +
== Console Commands  ==
 +
 
 +
Very good information about all of the supported commands and their effects can be found [http://www.mozilla.org/rhino/shell.html here].

Latest revision as of 21:43, 14 January 2011

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