[英]How to start java nashorn with jjs arguments
I would like to read a bytecode generated by nashorn engine. 我想读一下nashorn引擎生成的字节码。 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
我发现我需要的参数是
-d=*folder*
我也想应用乐观类型以获得更好的性能,这些类型由参数-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. 但我还没有找到我应该把jjs参数放在哪里。
The javax.script
API doesn't let you pass these arguments. javax.script
API不允许您传递这些参数。 You'll need to use the explicit Nashorn API to get a script engine factory: 您需要使用显式Nashorn API来获取脚本引擎工厂:
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. 添加到Attila所说的内容:您可以使用要传递给Nashorn的参数设置“nashorn.args”System属性。
Pro: You can stick to javax.script API in your code and still pass arguments. Pro:您可以在代码中坚持使用javax.script API并仍然传递参数。
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. Con:这会影响在此过程中创建的所有nashorn引擎 - 而nashorn特定的API允许您使用不同的命令行参数创建不同的引擎实例。 Also, you may not have control over System property setting in certain deployments.
此外,您可能无法控制某些部署中的系统属性设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.