Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
JavaScriptRhinoEngine.java - 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, sjp-1_0-fr-ri.zip,
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, sjp-1_0-fr-ri.zip, 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;
break;
}
}
Here is the entire example program, JavaScriptRhinoEngine.java, that shows you how to select a specific script engine to run script code:
// Copyright (c) 2017 FYIcenter.com
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;
break;
}
}
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, JavaScriptRhinoEngine.java, with two JAR files from sjp-1_0-fr-ri.zip:
>\fyicenter\jdk-1.8.0\bin\javac JavaScriptRhinoEngine.java
>\fyicenter\jdk-1.8.0\bin\java
-cp .;\fyicenter\sjp-1_0-fr-ri\script-js.jar;\fyicenter\sjp-1_0-fr-ri\js.jar
JavaScriptRhinoEngine
Script Engines:
Engine name: Oracle Nashorn
Engine name: Mozilla Rhino
Selected...
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-1.7.7.1.jar
⇐ JavaScriptEngineList.java - Load SJP Reference Implementation
2017-07-21, ∼2400🔥, 0💬
Popular Posts:
Xalan-Java, Version 2.7.1, is an XSLT processor for transforming XML documents into HTML, text, or o...
Java Architecture for XML Binding (JAXB) is a Java API that allows Java developers to map Java class...
JRE 8 deploy.jar is the JAR file for JRE 8 Java Control Panel and other deploy tools. JRE (Java Runt...
JDK 17 java.rmi.jmod is the JMOD file for JDK 17 RMI (Remote Method Invocation) module. JDK 17 RMI m...
JDK 17 java.base.jmod is the JMOD file for JDK 17 Base module. JDK 17 Base module compiled class fil...