Getting Started with JRuby - Tutorial at RailsConf rails

Earlier today, I attended Charles Nutter and Thomas Enebo "Your First Day with JRuby on Rails" tutorial at Rails Conf 2007. The key message is Ruby as the programming language and Java for the platform and libraries provides the best of both worlds to developers.

 

JRuby is 100% pure-Java implementation of the Ruby programming language. The goal is to use the power of Ruby programming language and leverage the power of Java platform. Read a more detailed tutorial here. All Ruby scripts work with JRuby instead of the original C-based implementation. Also the goal is NOT an attempt to alter Ruby or add incompatible features. You can download JRuby implementation, unzip it and set JRUBY_HOME to the installation directory. Here is a sample JRuby code:

1. require 'java'
2. include_class 'java.lang.ArrayList'
3. include_class 'javax.swing.JFrame'
4.
5. list  = ArrayList.new
6. frame = JFrame.new("Ruby SWINGS!")
7. list << frame
8. list.each { |f| f.set_size(200, 200) }
9. puts frame.title

The code above shows how Ruby and Java code can be mixed with each other. Line 1 includes Java support. Line 2 imports Java classes. Line 5 and 6 creates a new variables using a mix of Java and Ruby syntax. Line 7 and 8 uses the instance variables in Ruby syntax. Line 9 prints the title of the frame. If you run this code using JRuby interpreter then you get:

%JRUBY_HOME%/bin/jruby sample1.rb
Ruby SWINGS!

Here are some of the differences (from the original C-based implementation) in JRuby:

  1. Database support - This is required only if you want to re-use existing JDBC connection pool. Otherwise native adapter works fine and is preferred because of performance reasons.
    1. Change 'database.yml' from

      development:
        adapter: mysql
        database: HelloWorld_development
        username: root
        password:
        host: localhost

      to

      development:
        adapter: jdbc
        driver: com.mysql.jdbc.Driver
        url: jdbc:mysql://localhost:3306/helloworld_development
        username: root
        password:
    2. Include "require 'jdbc_adapter'" in 'environment.rb'.
    3. Either set CLASSPATH to include JDBC driver (for example, MySQL Connector/J 5.0.5) or copy into 'work/jruby/lib' directory.
  2. No Native extensions (at least, not until ports are available). Today, Mongrel, Hpricot are available. Database support and RMagick are in progress.
  3. Command-line performance - JVM performs much better after the first boot so don't expect stellar command-line performance.

Here are some other points that the tutorial talked/showed:

  • Goldspike (nee rails-integration) that allows to WAR'up a RoR application.
  • Installation of GlassFish V3 as Ruby gem which will be released soon. This will allow the following interaction possible:

    gem install glassfish-rails
    jruby script/server glassfish
    => Starting GlassFish
    => Rails application on http://localhost:8080/8080
    => Rails application on http://localhost:8080/4848
    => Clustering enabled
    => Connecting pooling enabled
    => Load balancing enabled
    => Server Ready.
  • JvYAML is a Java port of RbYAML.- Java YAML 1.1 parser and emitter
  • Deployment of Mephisto on GlassFish V3
  • Powerful editing, code completion, re-factoring capabilities using NetBeans IDE 6 M9. You can find more details here.

The biggest pain point from the audience was Rails deployment. With JRuby and GlassFish, you can continue deploying your apps on Mongrel. Because of JRuby, it also allows you to deploy your RoR applications on GlassFish, open-source, production-quality, Java EE 5 compatible application server.

BTW, there is supposed to be wireless connectivity through out the conference but it's very spotty :(

Technorati: glassfish rubyonrails ror netbeans railsconf

Comments:

[Trackback] Arun Gupta was at the tutorial also, and his blog entry has additional information, including some code snippets. No Tags...

Posted by Inchoate Curmudgeon on May 17, 2007 at 06:17 AM PDT #

Is there an IDE support for jruby? thanks Dev articles

Posted by jruby fan on May 18, 2007 at 05:56 AM PDT #

NetBeans 6 (http://www.netbeans.org/community/releases/60/index.html) provides Ruby and JRuby support. Find out more at: http://www.netbeans.org/products/ruby/

Posted by Arun on May 29, 2007 at 02:25 AM PDT #

dsf

Posted by guest on October 22, 2008 at 07:29 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today