Running Your First Rails Application on JRuby Seattle WA

Work step-by-step to install Rails into your JRuby installation and get a simple Rails application up and running.

Local Companies

Benaroya Research Institute at Virginia Mason
(206) 341-1313
1201 9th Ave.
Seattle, WA
TA Netgables Pvt Ltd
1 206 623 0910
216 First Avenue South,
Seattle,, WA
MITS
(206) 789-8313
701 5th Ave.,
Seattle, WA
Advanced Computer Solutions Ltd.
(206) 624-7854
500 Union St.,
Seattle, WA
International Business Machines
(800) 426-4968
1200 5th Ave.,
Seattle, WA
Control Systems PNW, Inc.
(206) 344-5929
900 4th Ave.,
Seattle, WA
Information Miner
(206) 652-3425
601 Union St
Seattle, WA
Onvia, Inc.
(206) 282-5170
509 Olive Way
Seattle, WA
InBios International
(206) 344-5821
562 First Avenue S., Ste. 600
Seattle, WA
Envision Telephony, Inc.
(206) 621-9384
520 Pike St.,
Seattle, WA

provided by: 
Originally published at Internet.com


JRuby (the 100% pure Java implementation of the Ruby programming language) has been gaining more and more attention in the Java and Ruby communities. In my first JRuby article, "JRuby: Java and Ruby Together at Last," I showed some basic usage of JRuby, and closed the article with a small Swing sample written in JRuby. At that time, the current version of JRuby was 0.9.1. Since then, version 0.9.2 has been released with improved support for Rails. With this current release, the ability to run a simple Rails application has been added. In this article, you will upgrade to JRuby 0.9.2, create a simple Rails application, and run it on JRuby.

The Current State of Ruby on Rails Support in JRuby

With three official releases under its belt (0.9.0, 0.9.1 and 0.9.2), JRuby is almost at the milestone of fully supporting Ruby on Rails. This means that Ruby on Rails applications will be able to run on JRuby without modification. JRuby developers have been working hard to get JRuby to pass all tests of the Ruby on Rails test suite and as Charles Nutter (lead JRuby developer) notes in his latest Rails support status update, they are very close. With that in mind, you can get a Rails application up and running on JRuby to see what it entails. First, you need to upgrade to the latest JRuby version.

Upgrading to JRuby 0.9.2

The JRuby distribution comes as a tar.gz file. For this article, I will be working on a Windows-based system running Java SE version 1.5.0_10. The latest JRuby version is available at http://dist.codehaus.org/jruby/. The file to download is jruby-java5-bin-0.9.2.tar.gz. Uncompress the archive; you should end up with a jruby-0.9.2 folder which contained subfolders: bin, docs, lib and samples. You can add a JRUBY_HOME environment variable pointing to this directory and then add the %JRUBY_HOME%bin ($JRUBY_HOMEbin on UNIX) to your system PATH. The JRuby distribution's bin directory contains the jruby.bat file that is used to run the JRuby interpreter. Run the command jruby .version from the command line to test that the JRuby is working:



Click here for a larger image.

Installing Rails into JRuby

Now that you have JRuby 0.9.2 installed, you can install Rails into your JRuby installation. You will use JRuby's 'gem' command to download and install Rails:



Click here for a larger image.

The '.y .-no-ri .-no-rdoc' command line switches tell gem to install all dependencies, but skip the installation of Rails documentation (because this takes a very long time). As can be seen from the console, you installed rails, rake, activesupport, activerecord, actionpack, actionmailer, and actionwebservice.

So, you now have Rails installed in JRuby. You can verify this by looking into the JRuby installation directory:



Click here for a larger image.

As you can see, the version of Rails that was installed into JRuby is version 1.2.2. Creating Your First JRuby on Rails Application

You now can create your first JRuby on Rails application. Because you are running JRuby on Rails on Windows, you need to perform one extra step to allow you to use the Windows 'rails' and 'rake' commands. I assume you have an installation on Ruby and Ruby on Rails on your hard drive. You will need to copy the 'rails.cmd' and 'rake.cmd' files from the 'bin' directory of your Ruby installation over to the 'bin' directory of your JRuby 0.9.2 installation:



Click here for a larger image.



Click here for a larger image.

You will need to Issue to command '%JRUBY_HOME%/bin/rails myfirstjrorapp' to create a JRuby on Rails application called 'myfirstjrorapp'.



Click here for a larger image.

Change to the 'myfirstjrorapp' directory and run the command 'jruby scriptserver'. This will start the Rails built-in 'WEBrick' web server and start your application on port 3000:



Click here for a larger image.

If you get an error such as the following:



Click here for a larger image.

It means that your Ruby on Rails installation is older than the JRuby on Rails installation and therefore the 'myfirstjrorapp' is looking for the older Ruby on Rails version. In your case, the Ruby on Rails version is 1.2.1, but the JRuby on Rails version is 1.2.2. To fix this, edit the 'myfirstjrorappconfigenvironment.rb' file and update the RAILS_GEM_VERSION variable: # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '1.2.2' unless defined? RAILS_GEM_VERSION

Now, you can point your browser to http://localhost:3000/. you should see the following:



Click here for a larger image.

That is it. You have created your first JRuby on Rails application!

Conclusion

This article has provided you with a step-by-step process to install Rails into your JRuby installation and get a simple Rails application up and running. Take some time to look further into JRuby and Ruby on Rails and see what it has to offer you.

References

* Ruby: http://www.ruby-lang.org/en/ * Java: http://java.sun.com/ * Java Programming Language: http://en.wikipedia.org/wiki/Java_language * JRuby: http://jruby.codehaus.org/ * Bringing Ruby to the JVM: http://www.infoq.com/presentations/JRuby * JRuby Wiki: http://www.headius.com/jrubywiki/index.php/Main_Page * Sun hires JRuby developers: http://www.tbray.org/ongoing/When/200x/2006/09/07/JRuby-guys * Ruby on Rails: http://www.rubyonrails.org/ * SilvaSoft, Inc. weblog: http://jroller.com/page/silvasoftinc

About the Author

Dominic Da Silva (http://www.dominicdasilva.com/) is the President of SilvaSoft, Inc., a software consulting company specializing in Java, Ruby, and .NET-based web and web services development. He has worked with Java since the year 2000 and is a Linux user from the 1.0 days. He is also Sun Certified for the Java 2 platform. Born on the beautiful Caribbean island of Trinidad and Tobago, he now makes his home in sunny Orlando, Florida.

Author: Dominic Da Silva

Read article at Internet.com site

Featured Local Company

TA Netgables Pvt Ltd

1 206 623 0910
216 First Avenue South,
Seattle,, WA
http://www.saralweb.com

We pride ourselves in producing innovative designs and superior technology over a web. We assured to capture your company's image, its products and services. The "proof is in the pudding"--our clients' web sites consistently receive more hits than their competitors.

We have been working on Web development and Application for so many years, we assume that everyone understands the impact of the World Wide Web. Over the last decade we have watched the World Wide Web become the most dynamic and wide spread communication technology the world has ever known. The Web has revolutionized the way we work, play and communicate. It has become the method of choice to shop and research products for millions and billions people around the world!  If you’re not on the web, then people are just not interested in your business.

Related Local Event
Technology Thursdays: Cloud Computing
Dates: 9/23/2010 - 9/23/2010
Location: Chamber's office
Seattle, WA
View Details