Skip to content

Instantly share code, notes, and snippets.

@Bala-raj
Created May 9, 2016 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bala-raj/2893ee71e7208d7f44b67956eef30019 to your computer and use it in GitHub Desktop.
Save Bala-raj/2893ee71e7208d7f44b67956eef30019 to your computer and use it in GitHub Desktop.
package test;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class Testing {
public static void main(String arg[]) throws Exception{
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
// read script file
engine.eval(Files.newBufferedReader(Paths.get("/Volumes/Bala/Eclipse Mars/Workspace/ClientWebAccessFullHistory/constants.js"), StandardCharsets.UTF_8));
engine.eval(Files.newBufferedReader(Paths.get("/Volumes/Bala/Eclipse Mars/Workspace/ClientWebAccessFullHistory/war/js/newLayout/underscore.min.js"), StandardCharsets.UTF_8));
engine.eval(Files.newBufferedReader(Paths.get("/Volumes/Bala/Eclipse Mars/Workspace/ClientWebAccessFullHistory/war/js/Library/Moment.js"), StandardCharsets.UTF_8));
// engine.eval(Files.newBufferedReader(Paths.get("/Volumes/Bala/Eclipse Mars/Workspace/ClientWebAccessFullHistory/war/js/Library/Moment-TimeZone.js"), StandardCharsets.UTF_8));
engine.eval(Files.newBufferedReader(Paths.get("/Volumes/Bala/Eclipse Mars/Workspace/ClientWebAccessFullHistory/war/js/Library/phone-format.js"), StandardCharsets.UTF_8));
engine.eval(Files.newBufferedReader(Paths.get("/Volumes/Bala/Eclipse Mars/Workspace/ClientWebAccessFullHistory/war/js/newLayout/FullHistory/fullHistory.js"), StandardCharsets.UTF_8));
//engine.eval(Files.newBufferedReader(Paths.get("/Volumes/Bala/Eclipse Mars/Workspace/ClientWebAccessFullHistory/untitled.js"), StandardCharsets.UTF_8));
Invocable inv = (Invocable) engine;
//System.out.println(Files.newBufferedReader(Paths.get("/Volumes/Bala/Eclipse Mars/Workspace/ClientWebAccessFullHistory/untitled.js"), StandardCharsets.UTF_8).readLine());
// call function from script file
System.out.print(inv.invokeFunction("getManipulatedData",Files.newBufferedReader(Paths.get("/Volumes/Bala/Eclipse Mars/Workspace/ClientWebAccessFullHistory/untitled.js"), StandardCharsets.UTF_8).readLine()));
// URL fileUrl = getClass().getResource("js/WebWorker.js");
//
// engine.eval(Files.newBufferedReader(Paths.get(fileUrl.toURI()),StandardCharsets.‌​UTF_8));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment