The fine folk at Apress sent me a copy of Ola Bini‘s new book to review. The full title is “Practical JRuby on Rails Web 2.0 Projects – Bringing Ruby On Rails to the Java Platform”. Overall, it was a good read, and extremely valuable to anyone who is developing in JRuby. JRuby information and documentation is scarce and most of the time, a Google trawl does not give you good results on a JRuby related query. Ola’s is the first, and currently the only JRuby book available, and in my experience, the most valuable resource available to give you an all-round picture of JRuby capabilities and usage.

Audience
Despite comments on the cover, I would suggest that this book is not ideal for people new to Ruby / Rails. Ola jumps in the deep end quite quickly, and being a talented Ruby programmer, makes use of lots of shorthand, procs, code blocks etc which would likely be hard to follow for someone new to Ruby. Although there is a section at the back called “Ruby for Java programmers”, I think this would not be sufficient for somebody new to Ruby to understand all the code examples.

To get the most value out of the book, it would be good to have at least a basic understanding of Ruby and Rails (eg, having read Agile Web Development with Rails or messed around with Ruby/Rails a bit) and a basic understanding of Java syntax, deployment and Java EE.

What’s Covered?
The book is project based, so as to give context and useful examples of JRuby functionality. There are 4 projects:

  • The Store (Shoplet) – a standard Rails app running under JRuby using Active Record JDBC.
  • Content management system – general Java integration and using Java libraries for content rendering.
  • Administration System – using EJBs, JMX and discussion of JRuby deployment options.
  • Library System – JRuby as the “glue that never sets”. Using Java Web service frameworks and JMS from JRuby.

The Good

  • Teaches you how to do all those tricky bits which are half-Java and half-Ruby and can’t be easily found online, such as converting between Ruby and Java types, including JAR files, implementing Java interfaces, etc
  • Clever and concise Ruby code – I picked up some Ruby tricks reading Ola’s code.
  • Complex code snippets are generally well explained in text.
  • Useful tips on when to use Java libraries and when to use Ruby ones.
  • Generally good and interesting example projects which justified the use of JRuby and the techniques shown in the book.
  • Helpful discussion of JDBC and database connectivity options for JRuby.
  • Nice overview of the many JRuby deployment options.
  • Helpful “sidebars” about Java Enterprise Edition technologies.
  • Covers the strong areas of JRuby well – web applications and system integration.
  • Appendices provide useful reference information.
  • Nice section at the end on how you can get involved in JRuby.

The Less Good

  • Example views often contain table layouts, inline styles and other layout information that would be better done in separate CSS files.
  • Variable names in code could be more descriptive. This would make example code easier to follow.
  • Occasional odd spelling like “sur_name” and use of deprecated Rails features, such as “start_form_tag” (to be fair though, Rails API does change very quickly).
  • The title suggests that the book is about Web 2.0. There is a little token AJAX, and I suppose a content management system is a bit Web 2.0, but overall, buy the book if you want to know about JRuby, not Web 2.0.
  • Although REST is only mentioned briefly in a little sidebar, and not a focus of the book, I found the description of REST and CRUD a bit misleading, especially when considering PUT vs POST.
  • The discussion of JRuby deployment provides a good overview, but more in depth discussion of major options (eg, GoldSpike), and production configurations would be great.

Conclusion
As the best and only JRuby reference, I’d highly recommend you buy a copy if you are working in, or planning to work in JRuby. The book will help you to write JRuby applications which make good use of Ruby, Rails, Java libraries and Java Enterprise Edition features.