Ruby In Steel Archives

Back to -Ruby In Steel Archives

JRuby In Steel

Pep Up Your Ruby With Java!

Ruby.exe isn’t the only Ruby in town these days. I wrote about the Gardens Point Ruby.NET compiler recently. If you prefer Java, maybe Sun Microsystems’ JRuby project might tempt you. But can you run JRuby inside Ruby In Steel? You bet you can! If you don’t believe me, just follow this guide…

Note: This is an old article (2007) and does not describe our integrated JRuby product (announced in 2008).

Before you trying to run JRuby, you must have Java installed and operational. If you haven’t got Java and the Java Development Kit (JDK) you should go to the Sun Microsystems Java site to download and install everything you need.

Next you need to install JRuby. That is available on the JRuby Site at http://jruby.codehaus.org. Download one of the archives (the one I downloaded is called jruby-java5-bin-0.9.2.tar.gz which contains the pre-built JRuby files; some archives require that you build the files yourself) and extract it into a directory on your local hard disk. On my PC, I extracted the JRuby files and folders into a directory called G:\jruby-0.9.2). This directory contains the first level of JRuby subdirectories, \bin, \docs, \lib and \samples.

You will need an archive tool capable of extracting files from .tar.gz archives. I used WinRar from RarLabs: http://www.rarlabs.com/

You now need to set an environment variable, called JRUBY_HOME to point to the JRuby directory. You can do that from the Windows Environment Variables dialog. To load this, select Start Menu->Settings->Control Panel. In the Control Panel, double-click System to show the System Properties dialog. Click the Advanced tab, then the Environment Variables button. Beneath System Variables, click the New button. Now enter JRUBY_HOME as the Variable name and the full path to the installed JRuby directory (in my case, that’s G:\jruby-0.9.2\ – be sure to add the trailing ‘\’) as the variable value. Click OK.

Now add the JRuby\bin directory to the system path. You can either add the full path or you can simply add bin to the end of the JRUBY_HOME variable. You can do this once again from the ‘Environment Variables’ dialog. Select the PATH variable; click the ‘Edit’ button, scroll to the end of the existing path, add a semicolon followed by the path to the JRuby\bin directory. In my case, I added:

;%JRUBY_HOME%bin

Click OK to close the dialog. Then click OK to close the Environment Variables dialog. You can now test it out by opening a command prompt (Start Menu->Run, Enter cmd and click OK) and entering…

jruby -version.

It is possible, at this point that you may see a message stating:

You must set JAVA_HOME to point at your Java Development Kit installation

If so, you need to verify that you have installed the Java Development Kit and that there is a variable specifying its directory. This variable is set up in the same way we set up JRUBY_HOME earlier. In the Environment Variables dialog, click the New System Variables button and enter JAVA_HOME as the variable name, followed by the path to the JDK. For me that happens to be C:\Program Files\Java\jdk1.5.0_08\. Click OK and OK again to close the two dialogs.

Open a new command prompt (don’t try to re-use any open command windows as they will not automatically adopt any changes made to the environment) and, once again, enter:

jruby –version

All being well, JRuby should bow respond with its version number, like this:

ruby 1.8.5 (0) [java]

If not, then you need to verify all the preceding steps: Java and the JDK must be installed, JRuby with its ready-to-run libraries (‘.jar’ files in its \lib directory) must also be installed and the various environment variables and paths must be set up as explained above. Once you get JRuby to respond with its version number you are ready to move on.

Ready To Run

Before trying to get JRuby to work from within Ruby In Steel, make sure that it works from the command prompt. Open a prompt in the JRuby \samples directory (on my PC that’s G:\jruby-0.9.2\samples). To run one of the sample program, just enter its name after the jruby command. My first choice, strangely enough, is a program called beer.rb. To run it, I enter:

jruby beer.rb

The program runs and counts its way through the words of a rhyme…

73 bottles of beer on the wall, 73 bottles of beer.
Take one down, pass it around,
72 bottles of beer on the wall…

(and so on)

Thirsty work, JRuby programming, it would seem :-)

JRuby In Steel

Now, let’s see how to use JRuby with Ruby In Steel. First let’s put the \samples directory into the Solution Explorer. The easiest way to do this is to ‘convert’ its contents into a Ruby In Steel Solution. To do that select File, Open, Convert.

The Ruby Converter Wizard

In the Convert dialog, select Ruby Converter Wizard, check off ‘Create new solution’ and click OK. Your current project (if any) will now be closed and the ‘Convert Project’ dialog appears. Click the Browse […] button and select the JRuby \samples directory, then click OK. This will add the sample code to the Solution Explorer.

Now try running the beer.rb program again. Right-click the directory shown in the Solution Explorer and open a command window.

To run the program enter:

jruby beer.rb

If you get an error message stating that the command or path cannot be found, you may need to close down Visual Studio and start again. Let me explain why: it turns out that, if you have made changes to the environment variables and path while Visual Studio is still running, these will not percolate through to command windows that are opened from within Visual Studio. Now reload Visual Studio and try again. Once you succeed in running the sample from a command window opened from the Solution Explorer, it’s time to move onto the next step.

You can add JRuby as an External Tool which means that the standard Ruby interpreter, ruby.exe, will be retained as the default when running and debugging your programs but you will have access to JRuby as an alternative.

To add JRuby as an External Tool, select the Tools menu, then External Tools. In the External Tools dialog click Add to create a new Tools menu item. Now you can add the a title for the new menu item, a command to run the JRuby compiler and the fully qualified path to the active source file, $(ItemPath). Finally you may (optionally) set the initial directory. I’ve set this to the same directory as the source file, $(ItemDir).

Once that’s done, click the JRuby item on the Tools menu to run the currently selected file in a command window.

So How Does JRuby Measure Up…?

I’ve only been using JRuby for a short while and therefore can’t comment in depth on its compatibility or performance. What I can say, however, is that JRuby has run most the programs I’ve thrown at it without too many problems (the biggest glitch so far was an exception which occurred when it encountered a line of code that formats a Time value as a Float in a string). Overall, my initial impressions on compatibility with Ruby are favourable. My impressions on performance are less so. In my benchmark tests the standard Ruby (1.8.4) interpreter was consistently a good deal faster than JRuby.

My benchmark tests were not exhaustive and there is still time for the JRuby developers to add a bit of zip to the execution speeds, so I shall keep my fingers crossed that performance may yet improve. For in-depth benchmarking results I recommend Antonio Cangiano’s comprehensive tests of Ruby, JRuby and some other interpreters and compilers. You may also want to read Charles Nutter’s blog entry about the new JRuby compiler which he is developing and which, he claims, runs some benchmarks at about twice the speed of ruby.exe.

Things To Come

In the current release of Ruby In Steel, you are limited to selecting a single Ruby interpreter to use with your programs. Bearing in mind that there are now quite a few alternatives, including the ‘in-development’ YARV (Ruby 1.9) virtual machine, Ruby.NET and JRuby, it would obviously be good to be able to switch quickly from one target interpreter/VM/compiler to another. This capability is something we’ll add in a future release of Ruby In Steel. We already have an experimental version of the software ‘in house’ which integrates JRuby pretty smoothly into the Ruby In Steel workplace. Apart from debugging (which must be done with ruby.exe), we’ve found that JRuby can be substituted pretty cleanly for the default Ruby interpreter – you won’t lose any editing or IntelliSense features when using it. In fact, it is even possible to run JRuby right inside the docked Ruby Console!

Here you can see JRuby running in the interactive docked Ruby Console...
...and just in case you think we’ve cheated by taking a screenshot of the normal Ruby.exe interpreter, here’s another picture showing JRuby’s credentials:

As I said before (but I’ll say again to avoid any misunderstandings), you can’t run JRuby in the console of the current release version of Ruby In Steel. However, you will be able to do so in a forthcoming free update for registered users of Ruby In Steel Developer.

Bookmark and Share   Keywords:  JRuby  tools
© SapphireSteel Software 2013
buy silagra tablets budeprion xf in canada budeprion xl 189 in india ciprofloxacin er 1000 mg sildenafil citrate 100mg jelly in california rogaine shampoo cvs tadaga 10 buy bimatoprost online cheap fluticasone spr buy orlistat australia buy armodafinil fast testosterone undecanoate 40 mg medicinali bactrim buy dapoxetine cheap bactrim online in india ciprofloxacin tabs 500 mg in india memantine hcl buy sustanon 250 usa revlimid cost bupropion drug namenda xr http://www.nodo50.org/casc/?buy=572057 budeprion xl walmart about buy malegra fxt online alli orlistat http://www.nodo50.org/casc/?buy=576310 bactrim d letrozole mexico pharmacia buy dapoxetine usa in france cernos gel sun pharma fluticasone salmeterol price bactrim 400 buy dapoxetine australia in france order bupropion http://www.nodo50.org/casc/?buy=963986 generic bactrim ds oral tablet himalaya garlic tablets in uk http://www.nodo50.org/casc/?buy=876171 super p force online http://www.nodo50.org/casc/?buy=358759 ciprofloxacin 500 bactrim otc bupropion hcl 100mg tab bimatoprost lowest price http://www.nodo50.org/casc/?buy=376748 about bactrim ds mg buy tadalafil citrate liquid buy kamagra australia medicamento vasotec buy zithromax paypal medicine enalapril nuvigil 150mg in france buy oracea cheap buy cenforce 100 generic viagra cheap orlistate in mayami