Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
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 (309)
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, 1747🔥, 0💬
Popular Posts:
commons-lang-2.6.jar is the JAR file for Apache Commons Lang 2.6, which provides a host of helper ut...
What is the sax\Writer.java provided in the Apache Xerces package? I have Apache Xerces 2.11.0 insta...
What Is commons-logging-1.2.jar? commons-logging-1.2.jar is the JAR file for Apache Commons Logging ...
Apache Commons Lang 3 is the 3rd version of Apache Commons Lang, which provides a host of helper uti...
JLayer is a library that decodes/plays/converts MPEG 1/2/2.5 Layer 1/2/3 (i.e. MP3) in real time for...