Practical JRuby on Rails Web 2.0 Projects
One Minute Bottom Line
As the first of hopefully many authors addressing the useful synergy between Java and Ruby, Ola Bini does a masterful job in this work. His approach is extremely balanced, and he always attempts to use the right tool for the right job. His coverage of Ruby integration with Java enterprise-scale technologies such as EJB, JMX, and JMS is top-notch, and really showcases how Ruby can be coupled with Java to deliver enterprise-scale solutions. He does lose one star for readability. The book is almost completely
void of any screenshots showing the projects as they are being
implemented (around five according to my count). If you want to see any
of the results of the code the author presents, you have to get your
hands dirty and run it yourself. That being said, the book already
weighs in at 320 pages of text and source code, so screenshots would
have made it much longer. The author also often uses code that for me
was rather hard to understand and read. I'm guessing that this is
primarily due to my very shallow Ruby background. Don't let that deter
you from purchasing this book, however. It is a gem |
Review
The book kicks off with two introductory chapters, followed by descriptions of four "Web 2.0" projects, and some appendices.
Chapter 1 - Introduction
The author begins with a brief description of his journey from Java to
Ruby and finally to JRuby, followed by a brief history of Ruby, Rails,
and JRuby. He then discusses many of the motivations for JRuby on
Rails, followed by a brief tour of the entire book. This chapter served
as a great high-level orientation to the featured technologies and a
useful road map for what was to come.
Chapter 2 - Getting Started
Getting started was a very practical chapter, guiding the reader
step-by-step through setting up his or her computer for JRuby on Rails
development. The author instructs you on how to install Java, JRuby,
Rails, and many of the other useful RubyGems out there including Rake,
ActiveRecord-JDBC, etc. I ran into a bit of a hiccup trying to install
Mongrel, but a quick email to Ola solved my problems. Hopefully by the
time this review is released all will work as written. The chapter
closes with instructions on setting up a MySQL database for Rails
development. Walking through this chapter should give any reader a full
JRuby on Rails development environment on his or her platform of choice.
Project 1 - The Store (Shoplet)
Chapter 3 - Introduction to Rails
This chapter offered a bird's eye view of the Rails framework and
addressed almost every aspect of building a Rails application. The
author spends no more than a page on each subtopic, so further reading
is necessary if one wants to get in-depth knowledge in any area.
Fortunately many of these subtopics are covered as the reader walks
through the development of each project. Included are two useful
sidebars: a nice discussion of the Model-View-Controller (MVC) design
pattern on which Rails is based and a comparison between Rails and MVC
web frameworks from other languages.
Chapter 4 - Store Administration
This chapter officially begins the first of the four projects. The
Shoplet project is an online Amazon-like store that is implemented
purely using Ruby on Rails and could, with minor changes to the
database and environment configuration, be deployed in a standard Ruby
runtime rather than JRuby. The author guides you step by step through
creating the administration portion of the application, stepping
through models, migrations, validation, scaffolding, introducing Ajax,
layouts and styles, authentication, and testing. At the end of the
chapter, the reader will have a very broad taste of what it's like to
develop a web application with Rails.
Chapter 5 - A Database-Driven Shop
This chapter expands on chapter four's introduction to Rails while
completing the customer-facing portion of the Shoplet project. The
reader is shown how to make use of Rails' Inflector
class as well as custom routes to make a very nice product-browsing
menu. Next, the author steps the reader through creating the shopping
cart and checkout features. The reader is then introduced to more
validation and testing features, and is given a brief look at how Rails
could integrate with a real payment system. The chapter closes with a
useful overview of ActiveRecord-JDBC and the various supported
databases.
Project 2 - A Content Management System (CoMpoSe)
Chapter 6 - Java Integration
This chapter presents an awesome introduction to the various points of
integration between Ruby and Java within JRuby. The author introduces
the use of Java resources (including classes, primitives, and arrays)
from Ruby code, the extension of Java by implementing Java interfaces
and extending Java classes with Ruby classes, and the ability to work
with Java collections in almost the exact same way as you would work
with a Ruby collection. The author next introduces several "gotchas" to
beware of when interacting between Ruby and Java code. Finally, the
chapter concludes by discussing the various ways to use Ruby from Java,
including direct access to the JRuby runtime, the Bean Scripting
Framework (BSF), and the Java Scripting API (JSR 223).
Chapter 7 - A Rails CMS
This chapter formally introduces the second of the four projects:
CoMpoSe, a Rails content management system (CMS). This chapter handles
all portions of the CMS that don't actually deal with content
rendering. The author steps the reader through the creation of the
database migrations, models, layouts and CSS, controllers, and views.
While implementing the controller and views for the "Layout" portion of
CoMpoSe, the reader gets a special treat in seeing how to use Ajax (via
Prototype) to create a list that can be sorted by drag and drop. The
chapter closes with a step-by-step implementation of security for
CoMpoSe.
Chapter 8 - Content Rendering
The first portion of this chapter paints a broad stroke across the
landscape of content rendering, including Ruby XML Parsing, Java DOM
Parsing, Java SAX Parsing, Java DOM and XSLT, RedCloth (Textile),
BlueCloth (Markdown), ERb, YAML, and a few other solutions. By the end
of this section, the reader should have a great grasp of all of the
various options at his or her disposal for rendering content using
JRuby on Rails. The second portion of the chapter integrates the
learning from the first portion plus chapters six and seven to build a
nice rendering engine for CoMpoSe, here harnessing the power of Java
for parsing XML and Ruby for everything else.
Project 3 - An Administration System (Big Brother)
Chapter 9 - A JRuby Enterprise Bean
Probably the last thing I expected to see in a "Web 2.0" book was
coverage of Enterprise JavaBeans (EJBs), but that's exactly what the
author delivers. This chapter demonstrates exactly how to wrap a JRuby
service (here a sequence engine) inside an EJB. Useful sidebars include
an overview of EJBs, and a brief introduction to the GlassFish
application server. The reader is first guided through a pure JRuby
implementation of the service (without calling out to Java APIs),
followed by bootstrapping the JRuby runtime inside a stateless session
bean and then calling out to the JRuby service. The chapter closes with
deploying the service and then testing it from another basic JRuby
script. All in all a fascinating chapter.
Chapter 10 - An EJB-Backed Rails Application
This chapter continues the implementation of "Big Brother" by expanding
the client test script created at the close of chapter nine into a nice
JRuby library that can access all of the EJB's services. The reader is
then guided through implementation of a small Rails application that
can drive the EJB service. The beginning of the chapter is interrupted
by a sidebar giving a high-level overview of Java Management Extensions
(JMX), to which the chapter circles back around as the author
demonstrates how to control both the EJB service and the Rails
application using JMX.
Chapter 11 - Deployment
This chapter addresses one of the larger pain points in Ruby on Rails
development, that of deployment. The author first covers the various
pure Ruby on Rails solutions followed by a discussion of the various
options that JRuby brings to the table. He closes by offering up his
two recommended best practices for JRuby on Rails deployment: a Pack of
JVM Mongrels and WAR deployment using Goldspike.
Project 4 - A Library System (LibLib)
Chapter 12 - Web Services with JRuby
This chapter introduces what the author describes as "the most complex
application described in this book," the LibLib library integration
system. After reading the next three chapters, you'll likely agree.
However, the real power here is that the author demonstrates how to
harness JRuby to build exactly the kind of application many of us are
called on to write everyday - an integration of multiple, sometimes
legacy, systems powered by a modern web interface. The author begins by
describing how to use JRuby to interact with web services, particularly
the Amazon Web Service, to import book information into the library
system. He demonstrates dynamic client generation, as well as static
stub generation, using both SOAP4R, a Ruby-based implementation of the
SOAP 1.1 and WSDL standards, as well as Axis and XFire, which are Java
equivalents. The chapter closes with a sidebar discussing the popular
REST guidelines for web services.
Chapter 13 - JRuby and Message-Oriented Systems
This chapter begins with an introduction to message-oriented middleware
(MOM) and how it is used, particularly in legacy integration. It
continues by describing a legacy system (and its associated binary data
format) that the author has built for the purpose of demonstrating
legacy integration using the Java Messaging Service (JMS). After a
brief detour to consider ActiveMessaging, which is a Rails MOM
integration library, and Java Message-Driven Beans, the author guides
the reader step-by-step through building a JRuby client to the LibLib
legacy system. The chapter closes by demonstrating how Rails
applications can communicate with one another via JMS. This chapter is
probably the least readable of the book, particularly due to the rather
"arcane" nature of the code which is pretty typical of what you'd find
in legacy integration.
Chapter 14 - The LibLib Rails Application
After spending the previous two chapters deep in the guts of web
services and message-oriented middleware, this chapter comes back to
the surface, as the author demonstrates how to build a Rails
application that harnesses the libraries built in chapters twelve and
thirteen. This chapter feels much like the earlier chapters where Rails
applications were built, making detours where this particular project
is unique. A very nice addition is the section on deploying multiple
instances of the same Rails application.
Chapter 15 - Coda: Next Steps
Chapter fifteen stands alone as a call to action from the author to his
readers. The author describes many of the projects and subprojects in
the JRuby landscape and how readers can contribute. He closes by
discussing three interesting and challenging home projects whereby a
reader can contribute something brand new to the JRuby community.
Appendices
Appendix A - Ruby for Java Programmers
While far from a complete Ruby reference (please see the PickAxe),
this appendix provides useful coverage of the major features and idioms
of the Ruby language. In particular, it leverages your existing Java
knowledge and points out similarities and differences.
Appendix B - JRuby Reference
A useful reference for working with the Java integration features available in Ruby code when using JRuby.
Appendix C - Resources
A large and useful list of websites, mailing lists, blogs, and books
for further reading and research into Ruby, Rails, and JRuby.
- Login or register to post comments
- 4673 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)











Comments
Pat Eyler replied on Fri, 2008/01/25 - 10:36am