How to add arguments with the ScriptEngineManager method getEngineByName("nashorn")?
<p>I am using Nashorn with Java API 8. I would like to secure javascript execution to be sure the code can't call Java package. </p>

<p>It is possible as follow :</p>

<pre><code>NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine("-strict", "--no-java", "--no-syntax-extensions");
</code></pre>

<p>However, using <code>NashornScriptEngineFactory</code> directly is not really nice. </p>

<p>The good way is to use the <code>ScriptEngineManager</code>. The <code>NashornScriptEngineFactory</code> is the factory used by <code>ScriptEngineManager</code> to make an instance of <code>ScriptEngine</code>. It is explained in this <a href="https://docs.oracle.com/javase/8/docs/jdk/api/nashorn/jdk/nashorn/api/scripting/package-summary.html" rel="nofollow">documentation</a> :</p>

<blockquote>
  <p>This package provides the javax.script integration, which is the
  preferred way to use Nashorn. You will ordinarily do this to obtain an
  instance of a Nashorn script engine:</p>

<pre><code>import javax.script.*;
...
ScriptEngine nashornEngine = new ScriptEngineManager().getEngineByName("Nashorn");
</code></pre>
</blockquote>

<p>I did not found a solution to create a <code>ScriptEngine</code> using <code>ScriptEngineManager</code> with the ability to give some extra arguments like <code>"-strict", "--no-java", "--no-syntax-extensions"</code>.</p>

<p>can anyone help me in this matter ? Thank you in advance.</p>