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.
If you wonder what jjs stands for, it stands for Java JavaScript. The command is located in the JDK_HOME\bin directory. The command can be used to run scripts in files or scripts entered on the command-line in interactive mode. It can also be used to execute shell scripts.
GraalVM can step in as a replacement for JavaScript code previously executed on the Nashorn engine. GraalVM provides all the features for JavaScript previously provided by Nashorn. Many are available by default, some are behind flags, and others require minor modifications to your source code.
With the release of Java 11, Nashorn was deprecated citing challenges to maintenance, and has been removed from JDK 15 onwards. Nashorn development continues on GitHub as a standalone OpenJDK project and the separate release can be used in Java project from Java 11 and up.
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.
Adding to what Attila said: you can set "nashorn.args" System property with the arguments you want to pass to Nashorn.
Pro: You can stick to javax.script API in your code and still pass arguments.
Con: This affects all the nashorn engines created in the process - whereas nashorn specific API allows you create different engine instances with different command line arguments. Also, you may not have control over System property setting in certain deployments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With