Search code examples
javascriptjavanashorn

How to start java nashorn with jjs arguments


I would like to read a bytecode generated by nashorn engine. I have found that argument i need is -d=*folder* also i would like to apply optimistic types for better performace which are enabled by argument-ot

Im initializing the engine by calling methods:

ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
engine.eval(myscriptfile);

But I have not found where am i supposed to put the jjs arguments.


Solution

  • The javax.script API doesn't let you pass these arguments. You'll need to use the explicit Nashorn API to get a script engine factory:

    import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
    
    NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
    ScriptEngine engine = factory.getScriptEngine("--optimistic-types=true", "-d=someFolder");
    

    Hope that helps.