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:
RhinoJsFile.java - Running JavaScript Code from File
How to run JavaScript code from a file with Rhino JavaScript Java library?
✍: FYIcenter
Running JavaScript code from a file is easy.
Just following the example below:
// Copyright (c) 2017 FYIcenter.com
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import java.io.*;
public class RhinoJsFile {
public static void main(String[] args) throws Exception {
ContextFactory f = new ContextFactory();
Context c = f.enterContext();
Scriptable s = c.initStandardObjects();
FileReader js = new FileReader(args[0]);
c.evaluateReader(s, js, null, 1, null);
}
}
Prepare your JavaScript code file, Hello.js:
var name = "FYIcenter.com";
java.lang.System.out.println("Hello, welcome to "+name+"!");
Compile and run the example program, RhinoJsFile.java:
>\fyicenter\jdk-1.8.0\bin\javac -cp \fyicenter\rhino1_7R5\js.jar RhinoJsFile.java >\fyicenter\jdk-1.8.0\bin\java -cp .;\fyicenter\rhino1_7R5\js.jar RhinoJsFile Hello.js Hello, welcome to FYIcenter.com!
⇒ Running Examples Provided in Rhino
⇐ RhinoFunctionCall.java - Call JavaScript Function from Java
2017-08-08, ∼2202🔥, 0💬
Popular Posts:
HttpComponents Core Source Code Files are provided in the source package file, httpcomponents-core-5...
Snappy-Java is a Java port of the "snappy", a fast C++ compresser/decompresser developed by Google. ...
How to download and install iText7-Core-7.1.4.zip? iText7-Core-7.1.4.zip is the binary package of iT...
JDK 11 jdk.charsets.jmod is the JMOD file for JDK 11 Charsets module. JDK 11 Charsets module compile...
What Is commons-fileupload-1.3.3 .jar?commons-fileupload-1.3.3 .jaris the JAR file for Apache Common...