Rhino: Hello Rhino

Mozilla Rhino is a scripting engine for running JavaScript in Java.

Installation
Download the latest Rhino version from the Mozilla site at http://www.mozilla.org/rhino/download.html. Unzip the Rhino files to your Java libraries directory, e.g. c:\dev\java\mozilla. Look for the js.jar archive and include it in your CLASSPATH environment variable or in the CLASSPATH setting of your application.

On Mac edit your ~/.bash_profile file:

PATH=$PATH
CLASSPATH=$CLASSPATH:/Users/nl11087/dev/java/rhino1_7R4/js.jar
export PATH CLASSPATH


Run Rhino from commandline
You can run Rhino from the Rhino ‘js’ prompt. On Windows, to open the commandline go to Start, and in ‘search programs and files’ type ‘cmd’ to start the dos commandline. Then to run the js prompt type ‘java org.mozilla.javascript.tools.shell.Main’ and hit enter.


C:\>
C:\> java org.mozilla.javascript.tools.shell.Main
Rhino 1.7 release 3 2012 06 27
js>

To quit the Rhino shell run quit();.

From here you can start running JavaScript for Java code.

Hello Rhino

js> function hello(sayHelloTo) {
js> print('hello '+sayHelloTo);
js> }
js>
js> hello('rhino')
hello rhino
js>

Adding Java
A simple example of JavaScript using Java is a System.out.println Java statement in JavaScript for Rhino.

js> importPackage(java.lang);
js> System.out.println("hello");
hello

Links:
Mozilla Developer Network – Scripting Java

One thought on “Rhino: Hello Rhino

  1. arie de reus

    RC,

    Ik verlang erg naar a push soms. De dingen die hier staan hebben mijn afgelopen nacht heel kort gemaakt..Was in de swing ofzo. Programmeren is niet mijn kopje thee, alhoewel ik tussen de wijn wel thee drink hoor. De links rechts..allemaal gezien en gelezen.. The code was een mokerslag..thx.

    arie

    Reply

Leave a Reply to arie de reus Cancel reply

Your email address will not be published. Required fields are marked *