Testing JRuby 1.1 RC2
Of late my schedule has been a bit more hectic than I had hoped. So I haven’t had as much time I would have liked to play around with JRuby and Rubinius. But the other day I was finally able to find a little time. So I downloaded the latest JRuby 1.1 release candidate, which is RC2.
So far it has worked well. I hear that 1.1 is significantly faster than previous versions of JRuby. I cannot comment on that yet, because I haven’t begun playing around with the types of applications where speed would matter.
Installing it
I downloaded the .tar.gz package and installed it to /opt. Do this (as root):
# cd /opt # tar zxf /home/lorenzod/dl/jruby-bin-1.1RC2.tar.gz
After that you will want to either (1) add /opt/jruby-1.1RC2/bin to PATH or (2) create a few symlinks. I chose the symlink option.
# JD=/opt/jruby-1.1RC2/bin # ln -s $JD/jruby /usr/local/bin # ln -s $JD/jrubyc /usr/local/bin # ln -s $JD/jirb /usr/local/bin # ln -s $JD/gem /usr/local/bin/jgem
You can of course add all the links that you need. These were enough for me to get started. Note that I named the link to jruby’s gem jgem.
Testing the compiler
I wanted to see how well the JRuby compiler works. So, I quickly put together the following little test program.
1 #! /usr/bin/jruby
2
3 # Count the number of times the user clicks some buttons.
4
5 require ‘java‘
6
7 include_class ‘java.awt.GridLayout‘
8 include_class ‘java.awt.event.ActionListener‘
9 include_class ‘java.awt.event.WindowListener‘
10 include_class ‘java.lang.System‘
11 include_class ‘javax.swing.JButton‘
12 include_class ‘javax.swing.JFrame‘
13
14 class ClickButton < JButton
15 include ActionListener
16
17 def initialize(text)
18 @count = 0
19 @text = text
20 super "#{@text} (0)"
21 add_action_listener self
22 end
23
24 def actionPerformed(event)
25 @count += 1
26 self.text = "#{@text} (#{@count})"
27 end
28 end
29
30 class MainWindow < JFrame
31 include WindowListener
32 include ActionListener
33
34 def initialize
35 super "Click Counter"
36 set_layout GridLayout.new(5, 1)
37 @total = 0
38
39 1.upto 5 do |n|
40 button = ClickButton.new "Button #{n}"
41 button.add_action_listener self
42 add button
43 end
44
45 add_window_listener self
46 pack
47 end
48
49 def actionPerformed(event)
50 @total += 1
51 end
52
53 # Bah, humbug!
54 def windowActivated(event); end
55 def windowClosed(event); end
56 def windowDeactivated(event); end
57 def windowDeiconified(event); end
58 def windowIconified(event); end
59 def windowOpened(event); end
60
61 def windowClosing(event)
62 puts "Total clicks: #{@total}"
63 System::exit 0
64 end
65 end
66
67 MainWindow.new.set_visible(true)
First I tried to run it normally.
% jruby cc.rb
That worked fine. After a few seconds a Swing application popped up on my screen. Next I tried compiling it.
% jrubyc cc.rb Compiling cc.rb to class ruby/cc % ls ruby/ cc.class
To run this program I did the following:
% java -cp /opt/jruby-1.1RC2/lib/jruby.jar:. ruby.cc
It worked. JVM takes a moment or two to fire up, then the application window pops up. Of course, I haven’t looked into the options to jrubyc yet, but at least this was enough to get me started.
Next, I’ll want to try JRuby out in Netbeans. I haven’t tried JRuby on Rails yet, so that is something I want to dedicate some time to. So expect more on JRuby from me in the near future.


