title: How to call Nashorn from Java
body: <p>I have a batfile that I want to call from java. I made a nashorn script, that runs successfully from commandline and from Netbeans 'run' command. Here it is: </p>
  
  <pre><code>#!C:/Program Files/Java/jdk1.8.0_25/bin -fv
  $ENV.PWD = 'C:/Hydromodel/MapGenerate';
  $EXEC("cmd /c start cmd_all.bat");
  print ('finished!');
  </code></pre>
  
  <p>I try to call the script from java this way:</p>
  
  <pre><code>    public class RunCmd {
  
      public void nashornTest()   {
      ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
      try {
          Object eval = engine.eval("load('src/simple/a_test.js');");
          //Object eval = engine.eval(new FileReader("C:/_Udvikling/Maven/realtid_2014/src/main/java/simple/a_test.js"));
      } catch (Exception ex ) {
          Logger.getLogger(CmdTest.class.getName()).log(Level.SEVERE, null, ex);
      }        
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Both ways I get this error:</p>
  
  <pre><code>Severe:   javax.script.ScriptException: TypeError: Cannot load script from src/simple/a_test.js in &lt;eval&gt; at line number 1
  </code></pre>
  
  <p>Even if the javascript file is reduced to:</p>
  
  <pre><code>print ('hello!');
  </code></pre>
  
  <p>I also tried <a href="https://stackoverflow.com/questions/22644441/new-to-scripting-with-java-and-nashorn-any-tutorials?rq=1">this SO proposed way</a>
  The Error stays.
  I googled, but most people seem to use Linux or Mac when writing about Nashorn.
  Should I do anything special to call Nashorn from java on a Windows box?</p>
  
  <p>mbwiese </p>
  
  <p>I am running Netbeans 8 and JDK 8 with Glassfish 4.1 on Windows 7</p>