BT

JRake: Ant-Killer Combo of JRuby and Rake

by Obie Fernandez on Dec 30, 2006 |

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.

 

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Constructive criticism by Hani Suleiman

In the spirit of constructive criticism which I think ultimately improved the agile section of infoq, I'd like to comment on this ludicrous post.

The post, as can be expected given who posted it, does not serve the java community at all. It's a thinly disguised gloaty piece about how great ruby is. Now, Ruby might well be great, but do I now need to unsubscribe from the Java feed on infoq too because some idiot thinks that ruby related content belongs here?

Aside from the idiocy of the response, it's mildly offensive to have a thoughtworker post about something an ex-thoughtworker did, and then say that another thoughtworker finds it great. It's surprising to say the least to see what amounts to a bunch of people from one company applauding each other being considered 'content'.

Also, if you're so keen on maintaining that infoq is a cut above tss and has more to offer, it's inexplicable why a news article would say things like 'bat-shit', when even TSS on a bad day manages to churn out news items on a daily basis while still sounding at least vaguely professional.

Finally, the article seems to say one thing, then discuss another. I'm still utterly perlexed as to why we need an explanation of how to reload a servlet (something which any idiot can do these days, if you're rebuilding just to update a servlet you're a loser) as part of a news item about a new build tool. Last time I checked, build tools and hot-redeployment weren't exactly codependent features.

The Java content on infoq is usually pretty good, I hope this isn't the start of a new trend where we get more objectionable content that serves nobody in a cheap attempt to encourage more 'discussion' (read: flaming).

Additional systems by Tom Ayerst

If you are interested in Rake for java builds you might want to look at JRuby and Antbuilder antbuilder.rubyforge.org/ and Raven raven.rubyforge.org/ and a discussion about it here: blog.aslakhellesoy.com/articles/2006/12/18/buil...

Re: Constructive criticism by Martin Gilday

While I do not necessarily agree with all of your comments I do agree that this article seems rather redundant. A much more detailed and informative one was posted eariler in the month. www.infoq.com/news/2006/12/jrake-intro

Re: Constructive criticism by Kevin Williams

The previous article referred to compiling. This post refers to getting instant feedback in a web dev situation. I tried it last night, and it truly is wicked fast. This provides a unique feature that AFAIK the other builders mentioned don't do. So, should this post be Ruby only? I say no. How does instant feedback for Java web development interest the Ruby developer?

So, Java community, will you get all uppity and turn up your nose at this just because it's Ruby? What if it were done in Haskell? C#? D? If it helps you, use it! If not, move on. Java already integrates with many other languages (SQL, HTML, JavaScript, C, Python, etc.) so what's the big deal? Java and Ruby do work quite well together already, and it's only going to get stronger. Remember, Sun hired these guys, and they haven't buried the project like Microsoft would.

I do agree on the un-professional tone that things like "bat-shit" lend to an otherwise eye-opening post.

Re: Constructive criticism by Hani Suleiman

Kevin, I have no objection about this article in *theory*. In practice, instead of it being 'here's a neat thing for Java people' it's written as a thinly disguised fluff piece that boils down to 'use ruby not java'. Looking at the sample code, it actually requires that you know a fair bit of ruby, thus rendering it instantly useless to 99.9% of Java developers.

I'm all for new and innovative ways to build stuff, a servlet reloader as implemented in this example is certainly a nice niche toy that's worthy of mention for the 1% of projects that are trivial enough for it to work with, but let's not pretend it's relevant for the majority of Java developers, and lets call it what it is, a neat, albeit fairly useless for practical applications, little gizmo. I prefer the 'info' bit of 'infoq' to be info, not religion.

I'm assuming that most readers of the Java community on infoq are Java developers. Would you trust your news to some random guy who has sworn off Java, writes poorly, and spends most of his time babbling on about how amazing ruby is? Isn't that what the ruby community is for?

Re: Constructive criticism by david m

I agree that many Ruby advocates are obnoxious - I'm perfectly happy with Java and its immense ecosystem. I guess the point of the article is that JRuby can be part of the ecosystem, and here is a useful technique to obtain faster development turnaround time, something I do miss.

However, it is a distraction to have to set up and learn the basics of a new language (of which there are a zillion, each with its own special features) just for one task, and the article is very badly written. Rather than putting together scraps of attitude and background, which I really don't care about, a better article would have some background on the issue, would explain the solution and considerations for those of us who don't know everything there is to know. For example, from what I can tell (and I'm deferring to the experts), this solution reloads the entire app for any small change, which seems excessive.

Would be even nicer if the better article included a native Java solution.

Re: Constructive criticism by anjan bacchu

"Remember, Sun hired these guys, and they haven't buried the project like Microsoft would.
"

JPython, which was created by Jim Huggunin languishes today while IronPython sees more uptick after MS hired him. Let's check our facts, shall we ?

BR,
~A

Re: Constructive criticism by Obie Fernandez

Hani, when you're right you're right. Thank you for the constructive criticism. Given the previous coverage and the nature of the article, I decided to pull it from the Java queue. The gratuitous expletive has also been removed, which in retrospect I agree was not appropriate for InfoQ. I admit that the article could have been better written, but there was no conspiratorial intent to spur flaming.

How does this compare to Eclipse, etc. by Porter Woodward

Just curious on how this compares to using something like Eclipse, which gets you incremental compiles, etc. Depending on what plug-ins you're using, you can also get Tomcat to reload servlets, etc. Since the JVM is already loaded (you're running Eclipse) I find there's little delay when invoking in-process Java tools.

Having said that I also realize that it's usually a far cry from the ease of development in Eclipse (quickly seeing the effects of changes) - and actually packaging up an application for deployment to the data center.

Maven jetty plugin by Alexandre Poitras

Maven jetty plugin also offer this capability.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

10 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT