Getting Started with JRuby

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
=> "JRUBY RULES!"
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: http://gems.rubyforge.org
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/*
Password:
[z010101CA:~] admin$ which rails
rails is hashed (/opt/jruby/bin/rails)
[z010101CA:~] admin$ rails webstore
      create
      create  app/controllers
      create  app/helpers
     ........
[z010101CA:~] admin$ cd webstore/
[z010101CA:~/webstore] admin$ jruby script/server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> 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
24.6.105.152 - - [27/May/2007:07:01:20 GMT] "GET / HTTP/1.1" 200 7552
- -> /
24.6.105.152 - - [27/May/2007:07:01:20 GMT] "GET /javascripts/prototype.js HTTP/1.1" 200 71260
http://8.12.34.20:3000/ -> /javascripts/prototype.js
24.6.105.152 - - [27/May/2007:07:01:20 GMT] "GET /javascripts/effects.js HTTP/1.1" 200 38200
http://8.12.34.20:3000/ -> /javascripts/effects.js
24.6.105.152 - - [27/May/2007:07:01:21 GMT] "GET /images/rails.png HTTP/1.1" 200 1787
http://8.12.34.20:3000/ -> /images/rails.png
24.6.105.152 - - [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: JRuby.org.

6 Comments

  1. I assume someone would use this to (hopefully) help speedup the performance of Ruby.

    How does someone load balances JRuby? Does mongrel still apply? I would think not, though I’m not sure.

  2. @Tim: I haven’t looked closely at it, but from what Ben said about war file deployment on glassfish, I assume you could rely on a java appserver to do the load balancing for you. I’ve used JBoss in the past, and it was very rich in that department.

    @Joyent: In a similar vein to JRuby is a language called Groovy. It’s a very impressive project, and a really great environment to code in. Is there any likelihood of it appearing on TxD’s servers? Have you looked at Groovy at all?

  3. @Tim

    You load-balance it like “normal”, it’s on a port on a private IP and you direct traffic that way.

    No mongrel doesn’t apply, you could use the jruby/java port of it, but you’d use a java app server like glassfish instead.

  4. Please of please Joyent post more to the blog.

    I feel starved when there isn’t anything to read for days on end 🙂

Comments are closed.