InfoQ

News

JRake: Ant-Killer Combo of JRuby and Rake

Posted by Obie Fernandez on Dec 30, 2006 12:00 PM

Community
Ruby
Topics
JRuby,
Build systems
Tags
Ant,
JRake,
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.

 

10 comments

Reply

Constructive criticism by Hani Suleiman Posted Dec 31, 2006 2:06 AM
Re: Constructive criticism by Martin Gilday Posted Dec 31, 2006 9:56 AM
Re: Constructive criticism by Kevin Williams Posted Dec 31, 2006 10:41 AM
Re: Constructive criticism by Hani Suleiman Posted Dec 31, 2006 11:13 AM
Re: Constructive criticism by david m Posted Dec 31, 2006 11:56 AM
Re: Constructive criticism by anjan bacchu Posted Dec 31, 2006 3:25 PM
Re: Constructive criticism by Obie Fernandez Posted Jan 1, 2007 1:24 PM
Additional systems by Tom Ayerst Posted Dec 31, 2006 7:48 AM
How does this compare to Eclipse, etc. by Porter Woodward Posted Jan 1, 2007 10:25 PM
Maven jetty plugin by Alexandre Poitras Posted Jan 2, 2007 9:53 AM
  1. Back to top

    Constructive criticism

    Dec 31, 2006 2:06 AM 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).

  2. Back to top

    Additional systems

    Dec 31, 2006 7:48 AM by Tom Ayerst

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

  3. Back to top

    Re: Constructive criticism

    Dec 31, 2006 9:56 AM 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. http://www.infoq.com/news/2006/12/jrake-intro

  4. Back to top

    Re: Constructive criticism

    Dec 31, 2006 10:41 AM 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.

  5. Back to top

    Re: Constructive criticism

    Dec 31, 2006 11:13 AM 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?

  6. Back to top

    Re: Constructive criticism

    Dec 31, 2006 11:56 AM 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.

  7. Back to top

    Re: Constructive criticism

    Dec 31, 2006 3:25 PM 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

  8. Back to top

    Re: Constructive criticism

    Jan 1, 2007 1:24 PM 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.

  9. Back to top

    How does this compare to Eclipse, etc.

    Jan 1, 2007 10:25 PM 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.

  10. Back to top

    Maven jetty plugin

    Jan 2, 2007 9:53 AM by Alexandre Poitras

    Maven jetty plugin also offer this capability.

Exclusive Content

A Formal Performance Tuning Methodology: Wait-Based Tuning

Steven Haines talks about tackling web application performance tuning by proposing a method called wait-based tuning.

Shaw and Fowler About Forging a New Alliance

Shaw and Fowler talk about the need for a new relationship between the business department and the IT department. Studies have shown that projects mostly fail due to miscommunication between the two.

How to GET a Cup of Coffee

In this article, Jim Webber, Savas Parastatidis and Ian Robinson show how to drive an application's flow through the use of hypermedia in a RESTful application.

Archaeopteryx: A Ruby MIDI Generator

Eccentric artist turned overnight anti-celebrity, Giles Bowkett captures the heart and soul of RubyFringe as he demonstrates his revolutionary Archaeopteryx MIDI drum pattern generator.

Alexandru Popescu Discusses the InfoQ.com Site Architecture

InfoQ Chief Architect Alexandru Popescu discusses the InfoQ architecture, WebWork and DWR, Hibernate and JCR, Hibernate scalability, the new InfoQ video streaming system, and future plans for InfoQ.

LHC Grid: Data storage and analysis for the largest scientific instrument on the planet

higgs-event

The Worldwide Large Hadron Collider (LHC) Computing Grid provides data storage and analysis for the entire high energy physics community that will use the LHC.

Fostering Software Craftsmanship in a Corporate Setting

Scott talks about software craftsmanship represented by people responsible for their work, continuously learning, taking pride in their work, sharing knowledge and respecting professional standards.

Eric Nelson on Windows as a Web Platform

Eric Nelson explores Windows as a web platform using IIS 7.0 providing an architecture deep dive and striving to reduce the lines of code in web applications.