Example usage for javax.script ScriptEngineManager ScriptEngineManager

List of usage examples for javax.script ScriptEngineManager ScriptEngineManager

Introduction

In this page you can find the example usage for javax.script ScriptEngineManager ScriptEngineManager.

Prototype

public ScriptEngineManager() 

Source Link

Document

The effect of calling this constructor is the same as calling ScriptEngineManager(Thread.currentThread().getContextClassLoader()).

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
    engine.eval("loadWithNewGlobal('res/nashorn4.js')");
}

From source file:Main.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine jsEngine = manager.getEngineByMimeType("text/javascript");
    if (!(jsEngine == null)) {
        System.out.println("text/javascript MIME type retrieved:" + jsEngine);
    }/*from   w w w .ja v a  2  s .c o m*/
    ScriptEngine jsEngine2 = manager.getEngineByMimeType("text/vbscript");
    if (jsEngine2 == null)
        System.out.println("\nNo supported script engine found for text/vbscript MIME type.");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
    engine.eval("load('res/nashorn3.js')");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("JavaScript");
    String script = "printf('%d + %d = %d', 1, 2, 1 + 2);";
    engine.eval(script);//ww w  . j ava2 s .  c o m
}

From source file:GetEngineByName.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    /* Retrieve a ScriptEngine registered with the rhino name */
    ScriptEngine jsEngine = manager.getEngineByName("rhino");
    if (!(jsEngine == null)) {
        System.out.println(jsEngine);
    } else {/*w  w w.  j  av a2s. c  o  m*/
        System.out.println("\nNo supported script engine foundregistered as Rhino.");
    }
}

From source file:GetEngineByExtensionDemo.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    /* Retrieve a ScriptEngine that supports scripts with .js extension */
    ScriptEngine jsEngine = manager.getEngineByExtension("js");
    System.out.println(jsEngine);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("JavaScript");
    String script = "print('Hello', 'World!');";
    engine.eval(script);//from  ww  w . j a  v  a 2  s. c  om
    script = "print('Hello World!');";
    engine.eval(script);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("JavaScript");

    String script = "print(msg.toUpperCase());print(msg.indexOf('a'))";
    engine.put("msg", "java2s.com");
    engine.eval(script);/* w  w  w .j  av  a2 s.  c  o m*/
}

From source file:GetEngineByMimeDemo.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    /* Retrieve a ScriptEngine that supports the text/javascript MIME type */
    ScriptEngine jsEngine = manager.getEngineByMimeType("text/javascript");
    if (!(jsEngine == null)) {
        System.out.println("text/javascript MIME type retrieved:" + jsEngine);
    }/*from  ww  w . j a  va  2  s  .c  om*/
    ScriptEngine jsEngine2 = manager.getEngineByMimeType("text/vbscript");
    if (jsEngine2 == null)
        System.out.println("\nNo supported script engine found for text/vbscript MIME type.");
}

From source file:ObtainScriptEngine.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();

    ScriptEngine engine1 = manager.getEngineByExtension("js");
    System.out.println(engine1);/* w  ww.j  a  v  a2  s .co m*/

    ScriptEngine engine2 = manager.getEngineByMimeType("application/javascript");
    System.out.println(engine2);

    ScriptEngine engine3 = manager.getEngineByName("rhino");
    System.out.println(engine3);
}