Using a Rhino as a Workhorse
What is Rhino
Rhino is an old Netscape project that is now part of the Mozilla foundation (the name on the front page, is an old client friend Norris Boyd who used to be at ATG and is now at Google, hey Norris!). It is an open-source implementation of JavaScript written entirely in Java. In essence it’s a server based JavaScript engine that allows JS code to be run on the server rather than in a user agent (typically a browser).
So what do you use it for?
Rhino seems to get used for 3 uses.
- As a means to run JavaScript code on the server, or in a thicker client application.
- Traditionally if you aren’t using a browser, then JS is not an option for development but JS is so much more than just a browser based scripting language. There is a whole side of JS that is not supported by most browsers but that makes the language the ECMAScript power house that it actually is. If you’re developing and have JS resources being able to run JS on the server or on a thick client application can speed up development, and reduce the costs
- As a debugger.
- If you can run JS on the server, it naturally follows that you can test and debug on the server as well - maybe even in an automated way or as part of a build script. There are a great number of debugging applications, tools and extensions that are written in Rhino. To extend that theory even further, it is often found that the language you wish to debug is often the best language to do the debugging and that where you can use Rhino…..
- Build JS Tools.
- Being able to run tools like JsLint, Packer, Dojo Compressor, etc from within a server command line environment can greatly increase the speed and stability of applications build using JS. Being able to tie SVN commits to an automated ant build script that includes not only the application build and test system, but also build and test system for the UI Behavioral Layer is essential for todays modern applications that are reliant on their rich UI interfaces.
So what do I really want use it for?
We’ve touched on all the examples above at work, but in the main I like to be able to run JS tools from the command line. So I have a special Textmate bundle interacts with rhino in the command line and utilizes the power of JSLint and Packer. Andrew Dupont has a JS Bundle that does a similar thing but is a little more fancy, but I personally like my own version (mainly because it does exactly what it says on the tin, and in such a way that I could add new tools without it needing a Ruby developer to explain what’s going on).
I’ve include the bundle here, it’s not plug and play (unlike the other one), but it’s pretty easy to install:
- Download the most recent version of Rhino
- Unpack it and copy the contents (especially the js.jar) into
/library/Java/extensions/ - Download my tweaked version of JSLint.js and packer.js - both I have tweaked but only so they would work in my situation, I just couldn’t get them to play nicely out of the box, it might have been my issue, but I know the two attached above work, so i figured I’d share them
- Download the Rhino functions textmate bundle, unpack it
- Double click to install the bundle
- Start using them
As I have mentioned there is a more polished Javascript tools bundle that will probably make it’s way into the main bundled bundle (and rightly so), I have it installed and it is very nice and very official, but in case anyone out there is Textmate tweaker and just wants to see how else it can be done, I hope it’s of help to someone.
Other things the Rhino could do for you
The other use for Rhino I recently started using was to actually use Rhino as a JS command line tool for testing. I’d been restricted to doing with in a terminal window until the other day i found a rather nice idea on Todd Ditchendorf’s blog and managed to get it working within a Dashboard widget. So now all i have to do is copy my code > F12 > Paste > see result > back to work.
I’m also still on the prowl for a good and easy to use testing workflow for the UI side of web applications. Recently I’ve looked at httpUnit as an alternative to Selenium (which I’m still rather smitten with for it’s ease of setup. I’m still convinced that out there, is the ultimate Rhino based solution for automated unit testing of rich UI’s, I just haven’t found it yet.
About this entry
You’re currently reading “Using a Rhino as a Workhorse,” an entry on Jon Sykes
- Published:
- 03.21.07 / 7am
- Category:
- Uncategorized
QR Code for this Blog Post
No comments
Jump to comment form | comments rss [?] | trackback uri [?]