The Artima Developer Community
Sponsored Link

Ruby Community News Forum
Deploying a Rails Application on JRuby, Sun Java Application Server

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Deploying a Rails Application on JRuby, Sun Java Application Server Posted: Feb 13, 2008 4:21 PM
Reply to this message Reply
Summary
JRuby on Rails solves many of the deployment and scaling problems pure Ruby-based Rails applications may encounter. Sun's Uma Sabada provides a straightforward tutorial on how to deploy a Rails application on Sun's Java application server, using JRuby and the Goldspike plugin.
Advertisement

Although—or perhaps because—Ruby on Rails applications are quick to build and easy to maintain, deployment is often the hardest part of a Rails project. While Mongrel has helped integrate Rails with an Apache environment, a proper Rails deployment environment still requires a fair amount of steps and components. In addition, Rails' single-threaded model may require a significant amount of memory to serve a large number of users.

Equally important, no native Ruby runtime at the present equals the monitoring and instrumenting capabilities of the JVM, making Rails application deployment and management risky in an enterprise environment.

Enter JRuby, the fast-maturing Java-based Ruby runtime. Using JRuby, it is possible to consider a Rails application as effectively a Java Web application, and deploy and manage it inside a Java application server. In a recent blog post, Sun's Uma Sabada provides a clear tutorial on how to take a regular Rails application and deploy it as WAR file inside Sun's Java Application Server, in Deploying JRuby on Rails WAR on Sun Java System Web Server 7 Update 2.

Sabada refers to Joshua Fox's JavaWorld article on JRuby to explain the benefits of deploying Rails on top of a Java environment:

With JRuby, Rails applications can run alongside Java Web applications on existing Java EE application servers. These application servers have a strong technical infrastructure. On the human side, education programs, experienced developers and support personnel are commonly available. And simply by running on the JVM, these application servers gain the benefit of the immense optimization efforts put into the JVM over the last decade...

The JVM has a much more sophisticated security model than Ruby's, giving JRuby on Rails tools for dealing with Web applications' typical security challenges, including control of Ruby scripts received from various sources. It also includes built-in support for internationalization...

A tremendous variety of functionality is accessible through Java today. APIs such as JDBC and JMS (Java Message Service) are best in class, and many irreplaceable in-house or independent software vendor enterprise information systems are accessible through Java APIs. By using JRuby, Rails applications can call into existing Java libraries as easily as Java code can.

Sabada's tutorial offers these benefits to a Rails application:

Allows JRuby on Rails to co-exist with servlet/jsp based web-apps... Deploying to WS7U2 would automatically give all the web server advantages including scalability, performance and security... Availability of Monitoring, Clustering and Administration capability to JRuby on Rails apps...

It turns out there are only a handful of JRuby-specific steps in this process. One such step is to specify the JDBC URL in the database.yml file of a Rails application:

development:
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/moviestore_development
  username: root

In addition, the environment.rb Rails environment file will have to contain a snippet specifying Java and JRuby as the Ruby environment:

require File.join(File.dirname(__FILE__), 'boot') 

if RUBY_PLATFORM =~ /java/
   require 'rubygems'
   RAILS_CONNECTION_ADAPTERS = %w(jdbc)
end

Finally, you would use the Goldspike Ruby plugin to package a Rails application as a WAR file:

Java web applications are typically packaged as WAR files in preparation for distribution and deployment to Java EE servers. It is useful to be able to package Ruby on Rails applications in a similar form, to enable seamless deployment to Java servers.

With these steps, the resulting WAR file can be deployed on the Sun application server, using the command-line or graphical deployment tools.

What do you think of running a Rails application inside a Java application server?

Topic: JRuby 1.1 RC2 Brings Faster I/O, Better JIT Previous Topic   Next Topic Topic: Dave Thomas Explains Ruby Fibers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use