Skip to main content


developerWorks  >  Java technology | Web development | Open source  >

Reuse Java code in your Ruby on Rails applications

Cross the Ruby-Java divide with the Ruby Java Bridge

developerWorks

Level: Introductory

Santhosh Krishnamoorthy (santhoshk@in.ibm.com), Staff Software Engineer, IBM Software Labs, Bangalore

05 Jun 2008

Register now or sign in using your IBM ID and password.

The Ruby Java Bridge (RJB) lets you load Java™ classes directly to, and call them from, Ruby on Rails applications. This tutorial shows how you can put this toolkit to work by reusing your legacy Java Web application code in a modern Web development platform.

In this tutorial

Ruby on Rails (Rails) is a full-stack Web application framework written in Ruby — a feature-rich, free, simple, extensible, portable, object-oriented scripting language. Rails has gained immense popularity among Web application developers. With it, you can quickly and efficiently develop a Web application and deploy it into any Web container, such as IBM® WebSphere® or Apache Tomcat.

Before Rails and similar Web application development frameworks were available, the de facto standard tool for the job was the Java language, thanks to its platform independence and comprehensive API set. Many Java Web applications are still running, resulting in the ready availability of much useful, well-written Java code (loosely referred to in this tutorial as legacy code). Legacy Java code is usually packaged as a set of JAR files.

If you change your Web application development platform to Rails, you can reuse legacy Java code. The Ruby Java Bridge (RJB) is a toolkit that lets you load JAR files into your Rails application and access the methods and variables in them. This tutorial explains how to configure and use RJB in a Rails application.


Objectives

  • Download, compile, and install RJB

  • Set up RJB to access shared Java libraries

  • Load and access legacy Java code in a Rails application

Prerequisites

This tutorial assumes basic familiarity with the Java language, Ruby, and Ruby on Rails.


System requirements

This tutorial assumes that you are working on a Linux® system. (However, the steps are essentially the same for Windows®.) It also assumes that you have a working setup of Ruby on Rails. If not, the tutorial Resources has links to documentation that can help you install and configure Rails for your system.

RJB requires that you have a Java SDK installed on your system. If you need to, download the latest Java SE SDK for your platform and install it now.


To view the demos included in this tutorial, JavaScript must be enabled in your browser and Macromedia Flash Player 6 or higher must be installed. You can download the latest Flash Player at http://www.macromedia.com/go/getflashplayer/.


Duration

1 hour


Formats

html, pdf


Share this....

digg Digg this story del.icio.us del.icio.us Slashdot Slashdot it!


Back to top


Document options

Document options requiring JavaScript are not displayed


My developerWorks needs you!

Connect to your technical community