HTTPS SSH

rhino-js-engine

Takes Mozilla JavaScript engine Rhino (version 1.7.7.1) and builds an adapter for it so that it can be used in Java scripting.

Why would I want to use Rhino 1.7.7.1?

Java already has Java JavaScripting. In Java 7 it was a modified Rhino. In Java 8 it is a new engine called "Nashorn".

But maybe you have some technical reason why you prefer Mozilla's Rhino which has some special functionalities that are not in Nashorn.

Or you may want to use Java's JavaScript in Google App Engine, where even the Nashorn engine is not included.

How do I use it?

The code is a Maven project.

It is easy to change the included JavaScript engine from Rhino 1.7.7.1 to something else.

In your project, add rhino-js-engine as a dependency:

    <dependency>
        <groupId>cat.inspiracio</groupId>
        <artifactId>rhino-js-engine</artifactId>
        <version>1.7.7.1</version>
    </dependency>

You don't need to add Rhino itself since it is pulled in by rhino-js-engine.

In your java code, get the scripting engine called "rhino":

import javax.script.*;

ScriptEngineManager manager=new ScriptEngineManager();
ScriptEngine engine=manager.getEngineByName("rhino");

Now you can call the script engine methods:

engine.eval(program);