Getting Started with JRuby

June 07, 2007 - by jason

JRuby is something we’re very excited about as it bridges the gap between the Java and Ruby worlds, bringing a wide range of new advantages to developers.

You can take advantage of the mature JDBC, utilize Java Application Servers such as Glassfish for deployment with simple WAR’s rather than Capistrano, or use existing JavaBeans and business logic written in Java to plug into a much better framework.

We’re pleased to be the first infrastructure company to stand firmly behind JRuby, offering it as part of our standard Accelerator packages.

Getting started is easy. In our Accelerators you will JRuby 1.0.0RC2 in /opt/jruby. JRuby comes complete with the jruby interpreter which is used just like ruby, including friends gem, jirb, and more. Let’s take a look at how to get started:

[z010101CA:~] admin$ export PATH=/opt/jruby/bin:$PATH
[z010101CA:~] admin$ jirb
irb(main):001:0> string = 'JRuby Rules!'
=> "JRuby Rules\!"
irb(main):002:0> print string
JRuby Rules!=> nil
irb(main):003:0> string.upcase
irb(main):004:0> quit

It’s really that simple.

Want to do some JRuby on Rails work?

[z010101CA:~] admin$ which gem
gem is /opt/jruby/bin/gem
[z010101CA:~] admin$ gem list --local
*** LOCAL GEMS ***
sources (0.0.1)
This package provides download sources for remote gem installation
[z010101CA:~] admin$ sudo gem install rails -y
Bulk updating Gem source index for:
Successfully installed rails-1.2.3
Successfully installed rake-0.7.3
Successfully installed activesupport-1.4.2
Successfully installed activerecord-1.15.3
Successfully installed actionpack-1.13.3
Successfully installed actionmailer-1.3.3
Successfully installed actionwebservice-1.2.3
[z010101CA:~] admin$ sudo chmod +r /opt/jruby/bin/*
[z010101CA:~] admin$ which rails
rails is hashed (/opt/jruby/bin/rails)
[z010101CA:~] admin$ rails webstore
create  app/controllers
create  app/helpers
[z010101CA:~] admin$ cd webstore/
[z010101CA:~/webstore] admin$ jruby script/server
=> Booting WEBrick...
=> Rails application started on
=> Ctrl-C to shutdown server; call with --help for options
[2007-05-27 07:00:52] INFO  WEBrick 1.3.1
[2007-05-27 07:00:52] INFO  ruby 1.8.5 (2007-05-16) [java]
[2007-05-27 07:00:52] INFO  WEBrick::HTTPServer#start: pid=33409388 port=3000 - - [27/May/2007:07:01:20 GMT] "GET / HTTP/1.1" 200 7552
- -> / - - [27/May/2007:07:01:20 GMT] "GET /javascripts/prototype.js HTTP/1.1" 200 71260 -> /javascripts/prototype.js - - [27/May/2007:07:01:20 GMT] "GET /javascripts/effects.js HTTP/1.1" 200 38200 -> /javascripts/effects.js - - [27/May/2007:07:01:21 GMT] "GET /images/rails.png HTTP/1.1" 200 1787 -> /images/rails.png - - [27/May/2007:07:01:21 GMT] "GET /favicon.ico HTTP/1.1" 200 0
- -> /favicon.ico

There you go. No tricks, no gimmicks. Just start playing.

For those who don’t have a Joyent Accelerator, download JRuby here: