Java ScriptEngine load external Javascript file

Description

Java ScriptEngine load external Javascript file

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class Main {

   public static void main(String[] args) {
      ScriptEngineManager sem = new ScriptEngineManager();
      ScriptEngine nashorn = sem.getEngineByName("nashorn");
      /*from  w  ww.ja  v a 2 s. c  o m*/
      try {
          nashorn.eval("load('helloNashorn.js')");
      } catch (ScriptException ex) {
           ex.printStackTrace();;
      }
   }
}



PreviousNext

Related