Search code examples
javascriptrhino

Use a library in Rhino (Javascript)


I currently run Mozilla Rhino with this command:

java -classpath c:\Users\DNastri\Desktop\rhino1_6R2\js.jar org.mozilla.javascript.tools.shell.Main -opt -1 -f

Where can I download the package and how should I change the command to use in Rhino code the following library:

importPackage(org.json);

Solution

  • Better to use Rhino's native JSON via...

    import org.mozilla.javascript.NativeJSON;
    

    Even better, use http://phantomjs.org which is headless Chrome.

    http://phantomjs.org/examples provides many examples of various types of scripting you can implement. Anything you can do in Chrome, you can do in PhantomJS.

    Rhino has much less development than PhantomJS now, so if you're working on a long term project, likely best to explore PhantomJS.