title: Loading a javascript library in javax.script?
body: <p>I want to run <a href="http://vis.stanford.edu/protovis/" rel="nofollow noreferrer"><strong>Protovis</strong></a> javascript from Java and get the evaluated SVG code.  I am using javax.script.* to run the Javascript:</p>
  
  <pre><code>public static void EvalScript() throws Exception {
      ScriptEngineManager factory = new ScriptEngineManager();
      ScriptEngine engine = factory.getEngineByName("JavaScript");
      Object result = engine.eval("var vis = new pv.Panel().width(300).height(300)
          .add (pv.Line).data ([1,0.5, 0.1, 0.01, 0.001, 0.3, 0.2,0.1,1])
             .left (function () { return this.index * 30; })
             .bottom (function (d) { return d * 250; });
          vis.root.render();
          vis.scene[0].canvas.innerHTML;");         
      System.out.println(result);
  }
  </code></pre>
  
  <p>This would complain because I never loaded Protovis itself, as would ordinarily be done with</p>
  
  <pre><code>&lt;script type="text/javascript" src="../protovis-r3.1.0.js"&gt;&lt;/script&gt; 
  </code></pre>
  
  <p>Is there a good way, short of sourcing in the full Javascript into the eval() command, of loading a library when running Javascript through javax.script?</p>