BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News JRake: Ant-Killer Combo of JRuby and Rake

JRake: Ant-Killer Combo of JRuby and Rake

The closer JRuby gets to being usable in real development efforts, the faster the pace of innovation gets in the realm of solutions combining the best of Java and Ruby technology. Case in point: JRake, pet project of notorious ex-ThoughtWorker Matt Foemmel, which replaces Apache Ant build files with Rake scripts running in JRuby.

The ant-killing combo is getting caned by Martin Fowler himself, a long-time fan of Rake, who explains why he finds JRake desirable:

The thing with build scripts is that you need both declarative and procedural qualities. The heart of a build file is defining tasks and the dependencies between them. This is the declarative part, and is where tools like ant and make excel. The trouble is that as builds get more complex these structures aren't enough. You begin to need conditional logic; in particular you need the ability to define your own abstractions.
JRake goes beyond being a simple replacement for Ant scripts. It actually speeds up the development process significantly. Matt explains his motivation was achieving the productivity of dynamic languages:
What we really want is for Java code to work the same way that dynamically typed languages do: you change your code, hit "save", and view the results in the browser.
According to Matt, having to use Ant drove him crazy:
The Java virtual machine takes time to start up. Since most tools that deal with Java code (e.g. javac) are themselves written in Java, this means there is a rather annoying interval between when you invoke them, and when they start doing actual work. This delay may seem insignificant, but on a large project where a build consists of many calls to many tools and gets run many times a day, all that wasted time can really harsh your flow.
The solution leverages Jetty in an innovative way:
I think I've managed to achieve something close to this, by setting up a Jetty server to act as a kind of proxy for my main application. Whenever a request comes in, it performs the following steps:
  1. Calls out to the JRake script to compile any out-of-date code.
  2. Creates a new classloader, and uses it to reload the application's main servlet class.
  3. Creates an instance of the servlet and forwards the original HTTP request on to it.
The upshot is that I can now make changes in my IDE, and see those changes (almost) immediately in my browser. No new virtual machines are started up along the way, no extra alt-tabs are needed, and I don't have to worry about hitting the web page before the deploy is complete. These may seem like minor points, but when you're doing this stuff eight hours a day, those little annoyances can add up.
Projects like JRake paint a vivid future for Java and Ruby combinations.

 

Rate this Article

Adoption
Style

BT