List of usage examples for javax.script ScriptException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); String script = "print ('www.java2s.com')"; try {// w w w. j ava 2 s. c om engine.eval(script); } catch (ScriptException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { // Get the Nashorn engine ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); String script = "print(msg)"; try {/*from www.j a v a2 s . c om*/ engine.put("msg", "Hello from Java program"); engine.eval(script); } catch (ScriptException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); engine.put("a", 1); engine.put("b", 2); try {//from w w w . jav a 2 s .c om String expression = "(a + b) > 2"; Object result = engine.eval(expression); System.out.println(expression + " ? " + result); } catch (ScriptException se) { se.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { // Create a script engine manager ScriptEngineManager manager = new ScriptEngineManager(); // Obtain a script engine from the manager ScriptEngine engine = manager.getEngineByName("JavaScript"); // Store the script in a String String script = "print('hi from java2s.com!')"; try {/*from w w w .ja v a2s .co m*/ // Execute the script engine.eval(script); } catch (ScriptException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { // Get the script engine factory for Nashorn ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); ScriptEngineFactory factory = engine.getFactory(); // Get the script String script = factory.getOutputStatement("\"java2s\""); System.out.println("Syntax: " + script); // Evaluate the script try {//from w w w . j ava 2 s . co m engine.eval(script); } catch (ScriptException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from ww w.j a v a 2s . c o m ScriptEngineManager sem = new ScriptEngineManager(); ScriptEngine se = sem.getEngineByName("JavaScript"); String myExpression = "('abc' == 'xyz' && 'thy' == 'thy') || ('ujy' == 'ujy')"; System.out.println(se.eval(myExpression)); } catch (ScriptException e) { System.out.println("Invalid Expression"); e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); engine.put("a", 1); engine.put("b", 5); Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); Object a = bindings.get("a"); Object b = bindings.get("b"); System.out.println("a = " + a); System.out.println("b = " + b); Object result;//w ww.j a v a 2s.co m try { result = engine.eval("c = aaaa + bbbb;"); System.out.println("a + b = " + result); } catch (ScriptException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.lehman.ic9.ic9Main.java
/** * Program entry point./* www .j a v a 2 s .c om*/ * @param args is an array of strings from the OS. */ public static void main(String[] args) { try { if (args.length >= 1) { if (parseScriptArgs(args)) { if (file.exists(script)) { // Load dependent jars in assemblyPath/lib-depends directory. jarLoader.getInstance().loadJarsInPathRecursively(sys.getAssemblyPath() + "lib-depends", debug); // Load dependent jars in assemblyPath/lib directory if any. jarLoader.getInstance().loadJarsInPathRecursively(sys.getAssemblyPath() + "lib", debug); // Create the Ic9 engine and eval the script. String[] engArgs = { "-scripting" }; ic9engine eng = new ic9engine(engArgs); eng.setMainArgs(script, scriptArgs); // Remove shebang if it exists. String contents = Pattern.compile("^#!/.*?$", Pattern.MULTILINE).matcher(file.read(script)) .replaceAll(""); eng.eval(script, contents); // If -t flag, attempt to call test() function. if (runTest) { eng.runTest(); } } else { System.err.println("File '" + script + "' couldn't be found."); } } } else { runInteractive(); } } catch (ScriptException e) { e.printStackTrace(); } catch (ic9exception e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void execute(ScriptEngineManager manager, String engineName, String script) { ScriptEngine engine = manager.getEngineByName(engineName); if (engine == null) { System.out.println(engineName + " is not available."); return;/*from w w w. j ava 2 s .c om*/ } try { engine.eval(script); } catch (ScriptException e) { e.printStackTrace(); } }
From source file:controllers.skilltag.SkillTagApp.java
@Transactional(readOnly = true) public static Result change(Long i, int seq) { List<SkillTag> skillTags = SkillTag.getAll(i, seq, "tag"); List<TagListVo> svs = new ArrayList<TagListVo>(); try {/* www. j a va 2 s . c o m*/ ScriptEngine engine = SemUtils.getEngine(); for (SkillTag st : skillTags) { TagListVo tv = new TagListVo(); tv.setTagName(st.tagName); // tv.setIsCurr(true); tv.setHref(controllers.skilltag.routes.SkillTagApp.list().url() + "?p=1&i=" + i + "&s=" + engine.eval("encodeURIComponent('" + tv.getTagName() + "')").toString()); svs.add(tv); } } catch (ScriptException e) { e.printStackTrace(); } return ok(play.libs.Json.toJson(svs)); }