title: ReferenceError: "alert" is not defined
body: <p>I am trying to call a java script function from java code.</p>
  
  <p>Here is my Java code</p>
  
  <pre><code>    public static void main(String[] args) throws FileNotFoundException {
      try {
          /**
           * To call a anonymous function from java script file
           */
          ScriptEngine engine = new ScriptEngineManager()
                  .getEngineByName("javascript");
          FileReader fr = new FileReader("src/js/MySpec.js");
          engine.eval(fr);
  
      } catch (ScriptException scrEx) {
          scrEx.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Here is my java script file:</p>
  
  <pre><code>(function() {
    alert("Hello World !!!");
  })();
  </code></pre>
  
  <p>But when I run main method of driver class it is giving me error as below:</p>
  
  <pre><code>Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "alert" is not defined. (&lt;Unknown source&gt;#2) in &lt;Unknown source&gt; at line number 2
  at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:110)
  at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:232)
  at Java6RhinoRunner.load(Java6RhinoRunner.java:42)
  at Java6RhinoRunner.main(Java6RhinoRunner.java:12)
  </code></pre>
  
  <p>What I know is that it need some script engine to execute it.</p>
  
  <p>For that I added rhino.jar file in to my class path.But this is not working.</p>
  
  <p>I an not getting how to solve this error.
  Please help.Thanks in advance.</p>