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$ jirbirb(main):001:0> string = 'JRuby Rules!'=> "JRuby Rules\!"irb(main):002:0> print stringJRuby Rules!=> nilirb(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 gemgem 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 -yBulk updating Gem source index for: http://gems.rubyforge.orgSuccessfully installed rails-1.2.3Successfully installed rake-0.7.3Successfully installed activesupport-1.4.2Successfully installed activerecord-1.15.3Successfully installed actionpack-1.13.3Successfully installed actionmailer-1.3.3Successfully installed actionwebservice-1.2.3...[z010101CA:~] admin$ sudo chmod +r /opt/jruby/bin/*Password:[z010101CA:~] admin$ which railsrails is hashed (/opt/jruby/bin/rails)[z010101CA:~] admin$ rails webstorecreatecreate  app/controllerscreate  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=300024.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 71260http://8.12.34.20:3000/ -> /javascripts/prototype.js24.6.105.152 - - [27/May/2007:07:01:20 GMT] "GET /javascripts/effects.js HTTP/1.1" 200 38200http://8.12.34.20:3000/ -> /javascripts/effects.js24.6.105.152 - - [27/May/2007:07:01:21 GMT] "GET /images/rails.png HTTP/1.1" 200 1787http://8.12.34.20:3000/ -> /images/rails.png24.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.



Post written by jason