Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

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

        ScriptContext defaultCtx = engine.getContext();
        // Work with defaultCtx here

        // Create a new context
        ScriptContext ctx = new SimpleScriptContext();

        // Configure ctx here

        // Set ctx as the new default context for the engine
        engine.setContext(ctx);

        ctx.setBindings(manager.getBindings(), ScriptContext.GLOBAL_SCOPE);

        engine.setContext(ctx);
    }
}