- Select SJP RI Engine: Rhino


How to select the SJP Reference Implementation Script Engine, Mozilla Rhino, to run my JavaScript code? I don't want to use the default JavaScript engine.

✍: FYIcenter


If you have the SJP Reference Implementation Script Engine,, installed, you select it to run your JavaScript code instead of using the default script engine, Oracle Nashorn.

1. Make sure 2 JAR files from the SJP Reference Implementation package,, are installed properly:

>dir \fyicenter\sjp-1_0-fr-ri

07/27/2006  01:09 PM           701,049 js.jar
10/16/2006  07:00 PM            34,607 script-js.jar

2. Get all available script engine factories:

      ScriptEngineManager m = new ScriptEngineManager();
    List<ScriptEngineFactory> l = m.getEngineFactories();

3. Loop through the factory list, and select "Mozilla Rhino" engine:

    ScriptEngineFactory f = null;
      for (ScriptEngineFactory i : l) {
         if (i.getEngineName().equals("Mozilla Rhino")) {
      f = i;

Here is the entire example program,, that shows you how to select a specific script engine to run script code:

// Copyright (c) 2017
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import java.util.*;

public class JavaScriptRhinoEngine {
   public static void main(String[] args) throws Exception {
      ScriptEngineManager m = new ScriptEngineManager();
    List<ScriptEngineFactory> l = m.getEngineFactories();
    ScriptEngineFactory f = null;
      System.out.println("\nScript Engines:");
      for (ScriptEngineFactory i : l) {
         System.out.println("   Engine name: "+i.getEngineName());
         if (i.getEngineName().equals("Mozilla Rhino")) {
        System.out.println("      Selected...");
      f = i;
      ScriptEngine e = f.getScriptEngine();
      System.out.println("\nFrom Mozilla Rhino:");
      e.eval("print('   Hello world!')");

      System.out.println("\nJavaScript engine info:");
      System.out.println("   Engine name: "+f.getEngineName());
      System.out.println("   Engine version: "+f.getEngineVersion());
      System.out.println("   Language name: "+f.getLanguageName());
      System.out.println("   Language version: "+f.getLanguageVersion());
      System.out.println("   Engine class: "+e.getClass().getName());
      System.out.println("   Factory class: "+f.getClass().getName());
      System.out.println("   Manager class: "+m.getClass().getName());

Compile and run the example program,, with two JAR files from


   -cp .;\fyicenter\sjp-1_0-fr-ri\script-js.jar;\fyicenter\sjp-1_0-fr-ri\js.jar 

Script Engines:
   Engine name: Oracle Nashorn
   Engine name: Mozilla Rhino

From Mozilla Rhino:
   Hello world!
JavaScript engine info:
   Engine name: Mozilla Rhino
   Engine version: 1.6 release 2
   Language name: ECMAScript
   Language version: 1.6
   Engine class: com.sun.script.javascript.RhinoScriptEngine
   Factory class: com.sun.script.javascript.RhinoScriptEngineFactory
   Manager class: javax.script.ScriptEngineManager


Download Rhino to SJP Wrapper rhino-js-engine- - Load SJP Reference Implementation

SJP (Scripting for the Java Platform) API

⇑⇑ FAQ for Rhino JavaScript Java Library

2017-07-21, 1638🔥, 0💬