Rhino (JavaScript engine)
From Wikipedia, the free encyclopedia
Rhino is an open source JavaScript engine. It is developed entirely in Java and managed by the Mozilla Foundation. The Foundation also provides an implementation of JavaScript in C known as SpiderMonkey.
Rhino converts JavaScript scripts into Java classes. Rhino works in both compiled as well as interpreted mode. It is intended to be used in server-side applications, hence there is no built-in support for the browser objects that are commonly associated with JavaScript.
Rhino can be used as a debugger by making use of the Rhino shell. It can be used in applications by embedding Rhino.
A slightly modified version of Rhino 1.6r2 comes bundled with the Sun release of Java SE version 6, which was released in December 2006. This makes it easier to integrate JavaScript as part of Java programs and to access Java resources from JavaScript. Other implementations of Java 6 may differ: for instance, the version of Java 6 supplied by Apple for Mac OS X does not include a JavaScript engine. [1].
Contents |
[edit] History
The Rhino project was started at Netscape in 1997 and released to the Mozilla Foundation in 1998. It was made open source thereafter[2]. The project gets its name from the animal on the cover of the JavaScript book from O'Reilly Media [3].
The last 1.7R1 version relies on the Java 5 platform, and support version 1.7 of JavaScript[4].
[edit] Example
Below is an example of java code running JavaScript print('Hello, world!')
import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class RhinoEngine { public static void main(String[] args) { ScriptEngineManager mgr = new ScriptEngineManager(); // Now we can go and get a script engine we want. // This can be done either by finding a factory that supports // our required scripting language // (engine = factory.getScriptEngine();) // or by requesting a script engine that supports a // given language by name from the script engine manager. ScriptEngine engine = mgr.getEngineByName("JavaScript"); // Now we have a script engine instance that // can execute some JavaScript try { engine.eval("print('Hello, world!')"); } catch (ScriptException ex) { ex.printStackTrace(); } } }
[edit] See also
[edit] References
- ^ Smart, John Ferguson. The Mustang Meets the Rhino: Scripting in Java 6. ONJava.com (O'Reilly Media). Retrieved on 2006-12-26.
- ^ Rhino History. Mozilla Foundation. Retrieved on 2008-03-20.
- ^ O'Reilly's Javascript book, inspiration for the Rhino name
- ^ New in Rhino 1.7R1. Mozilla Foundation. Retrieved on 2008-03-20.
[edit] External links
|
|