Recently on the JRuby mailing list, a call went out for all the crypto-jrubyists to come out of their holes and tell the world about their experience with JRuby. I believe the call was inspired by this blog post by Brian Tatnall. So, I figured I’d throw in my two cents.
Unlike Brian, I am not someone who “works with Rails every day”. In my job, I do a lot of Java, C++, Tcl, and maybe some Python when I get lucky. I’ve heard a lot of good things about Ruby, but have never had the chance to try it out on a project. Adding yet another language to one of our systems would just be mean. So I tried Ruby a few times, liked it, and then forgot it.
Anyway, a few months ago an odd (for my company) project came along that required us to build a small webapp that does custom indexing and searching of a document repository. I should mention that not only am I a total Ruby noob, but I’m also a total webapp noob… In any case, this seemed like the perfect chance to learn something new and a colleague of mine had been playing around with Rails at home so we at least had that.
Some initial work had already been done using Lucene in Java and after talking with the customer, we learned that they wanted to deploy the app on Tomcat 5.5. Enter JRuby.
We decided to go with JRuby (version 1.1.3 at the time). Since JRuby allows Ruby code to call into existing Java libraries, I decided to stick with the existing Lucene code in Java. Thus, I built a back-end indexer and query API in Java, while we built the web front-end in JRuby and Rails.
Honestly, it was almost too easy. Rails makes building the webapp sickeningly easy, especially for something as straightforward as what we were doing. Calling the Java-based query interface I had built was also a snap. I just imported my jar and started calling methods. The conversion from Java objects to Ruby objects was mostly seamless. I think I only had to resort to a couple of map calls to turn lists returned by the query interface into objects that Rails could use in its view templates.
I should note that jruby is actively supported by NetBeans and apparently in Aptana on Eclipse as well. For everything I was doing with Rails, I stuck with vim and the command-line. Rails already does way more magic than I understand and an IDE would just add one more layer to my ignorance.
I think the only “hack” I ended up with was a static list of query objects stored in Java and accessed from JRuby. Since the Rails controllers are stateless, I couldn’t figure out where I should store global app data, so for expediency, I put them in a global map. I’m very bad. I chalk this up to total ignorance of Ruby and Rails (more on this below).
We finished the first phase of development way under budget largely thanks to JRuby and Rails. Yay! This turns out to have been a good thing, because we needed that extra time when we went to deploy. Recall that we were going to deploy to the customer’s Tomcat server. Luckily, the Warbler tool makes this process mostly painless. Given a Rails app, Warbler packages everything up and generates a war file.
I had a few issues with Warbler. First, there was some inconsistency in what command to actually run. In some documentation, it said to “warble”, when the command was really “warbler”, or vice versa, I don’t remember. Second, it took me a little while to figure out the right method of specifying the gems and Java libraries that my app depended on. I recall spending a day fiddling with Tomcat, trying to make sure my jars were discovered as well as the right JDBC ActiveRecord adapter, etc. I think this again has more to do with my ignorance than any actual problems with Warbler.
So I set up a box that mirrored the customers setup and documented the deployment process. Unfortunately, the customer was in another state which meant the install was actually going to be done by a coworker in that state who knew even less about this stuff than me. It took her a day or two of phone calls clarifying everything I’d missed in my installation guide, but eventually, everything worked and we had a working webapp!
I should also mention that more than half of the install time was spent on issues with my Java indexer. JRuby wasn’t really much of a problem.
The Conclusion and p.s. I Don’t Know Ruby
So, the project was really a success. Even with the deployment hassles, we were still under budget, impressed the customer and were able to get follow-on funding to add features. Thanks JRuby!
However, while I was working on the project, I noticed a phenomenon I had read about here. I had built and deployed Ruby on Rails app and can safely say that I barely know Ruby any better than I did when I started. Rails does so much work for you that you can get by without really knowing any Ruby at all. That’s a little sad, since projects like this are usually the only time I get to really learn a new language in any depth. Maybe I need to start with a pure Ruby app. I’ve been thinking that a lot of the Swing UI code I’ve been doing for the jsoar debugger would be quicker and more educational if it was done in jruby, or one of the other JVM-based languages that have been multiplying like rabbits lately. We’ll see.
Here are other JRuby testimonials and I’ve come across: