Warbler, A Little Birdie To Introduce Your Rails App To Java

Posted by Nick Sieger Tue, 04 Sep 2007 02:48:40 GMT

This week I was working on integrating the latest JRuby 1.0.1 and Goldspike 1.3 releases into our environment, when my frustration hit a fever pitch.

See, I had always thought that the .war packaging side of Goldspike was a little clunky and un-ruby-like, but I didn’t see a clear path to fixing it. I had heard little complaints about it here and there: the little configuration DSL didn’t give you enough control or wasn’t documented well enough; the fact that it downloads libraries from the internet during assembly (convenient, but not safe or reproducible for production deployments).

Also, in my own opinion it took the wrong approach to packaging Rails in a .war file. It puts the Rails application directory structure into the root of the .war file where any web server or Java application server might mistakenly serve up your code as static content. The Java .war file spec has this special directory called WEB-INF expressly for the purpose of hiding that stuff away, so why not use it?

And then, suddenly Goldspike was packaging up my entire Rails application directory, .svn directories and everything. So I set out to fix this once and for all.

And so I present Warbler. A little bird who chirpily steps up to the task of assembling your Rails application into a Java Web Archive (.war). Here, get it:

gem install warbler

And then, in the top directory of your Rails application,


Those two steps are all it takes to make a .war file, including your application and recent versions of JRuby and Goldspike, that’s deployable to your favorite Java application server.

There are a number of points about Warbler worth mentioning.

Does one thing, well

Warbler only packages, and doesn’t care about anything else, like how to dispatch servlet requests to Rails. This will allow for more runtime servlet binding mechanisms to take advantage of Warbler in the future.

Fast and lightweight

50% less code than the Goldspike packaging plugin, yet does the job quickly and efficiently.

Sane defaults

Warbler only packages code that you need to run the application, omitting database migrations and tests. If your application is self-sufficient (no external dependencies), then the out-of-the-box configuration will probably work for you. Public HTML/images/javascript/stylesheets go in the root of the webapp, where Java webservers expect them to be.

Documented, flexible configuration

Need to customize your configuration? Run warble config and edit config/warble.rb. All the options are there, commented and documented.

Need to change out the bundled JRuby/Goldspike versions? warble pluginize makes a copy of Warbler in the vendor/plugins area of your application, allowing you to change the .jar files in the vendor/plugins/warbler-0.9/lib directory. Warbler then makes his nest in your project’s list of rake tasks (as rake -T | grep war shows)

rake war            # Create trunk.war
rake war:app        # Copy all application files into the .war
rake war:clean      # Clean up the .war file and the staging area
rake war:gems       # Unpack all gems into WEB-INF/gems
rake war:jar        # Run the jar command to create the .war
rake war:java_libs  # Copy all java libraries into the .war
rake war:public     # Copy all public HTML files to the root of the .war
rake war:webxml     # Generate a web.xml file for the webapp

Warbler even omits himself in the .war file produced when running in plugin mode, since you won’t need him at runtime. It’s the little details that matter.

Give him a try and let me know if it makes your life deploying Rails applications to JRuby on Java appservers easier!

Tags , ,  | 13 comments


  1. Avatar Jonathan Bartlett said 1 day later:

    Very nice! However, when when my app boots, it says ” Failed to load Rails: Could not find RubyGem jruby-openssl (>= 0.0.0)”

    I tried just a plain-Jane test app, but it can’t find my database module “postgres”.

    I think this is because these need extra JRuby-specific gems. How would I load them using warbler?

    I can get both of these running using plain JRuby very easily by just using JRuby’s gem installation function. Do I need to copy folders from my local JRuby installation or is there some way to automate it with warbler?

  2. Avatar Nick said 1 day later:

    If you have custom gems (including jruby-openssl in this case), you’ll have to tell warbler about them.

    Set up a config/warble.rb file with warble config, and edit it. There’s a spot to add gems by name there. As long as they’re present in the JRuby installation where you run warbler (or rake) from, they’ll get copied into your .war file.

  3. Avatar Stéphane Boulanger said 3 days later:

    Nice job Nick!

    First, with the 0.9 version, I received a undefined method `exitstatus' for nil:NilClass error. I think this was due to my (old) rake version. Upgrading warbler to 0.9.1 with gem update warbler --include-dependencies solved my problem!


  4. Avatar Jeff Cooper said 6 days later:

    When I create a war file and try to run in tomcat, on startup i get a no class found for org/apache/commons/pool/PoolableObjectFactory for SEVERE: Error configuring application listener of class org.jruby.webapp.RailsContextListener. I looked in the WEB-INF\lib directory and see commons-pool-1.3.jar. Does anyone know how to solve this. Thanks


  5. Avatar Nick said 6 days later:

    @Jeff: Interesting, I haven’t seen that issue yet. Can you send more details to me in an email?

  6. Avatar Stéphane Boulanger said 7 days later:

    Problem revised: It was not due to rake. The command to unpack the gems did not succeed on my system. But after calling warble several times, the specs of the gems were present in the working directory and warble presumed all gems were correctly unpacked and build the war file... and making me think, my updating of rake had “solved” the problem.

    @Nick: I fixed it my sources. It uses Gem::Installer directly to unpack the gem. Should I send you the snippet?

  7. Avatar Joslyn said 7 days later:

    When I try installing the gem I get a buffer error: “ERROR: While executing gem ... (Zlib::BufError)”

    Anyone else getting this or have any suggestions. I was excited to see this tool after running into no luck with any of the deployment tutorials.

  8. Avatar Nick said 7 days later:

    @Stephane: please send it, I’d be happy to incorporate it.

    @Joslyn: this is during install? Can you try downloading the gem from the downloads page and run gem install directly on the .gem file? And is this with Ruby or JRuby?

  9. Avatar Joslyn said 7 days later:

    I went ahead and completely reinstalled the latest ruby on my windows box and immediately tried installing warbler both remotely and from a local .gem.

    Both sill had the buffer error. I was able to install other gems (such as rails). Any other information you need?

    WinXP Pro SP2 Ruby 1.8.5-24

  10. Avatar Joslyn said 7 days later:

    Update: Wasn’t pointing to my JRuby path to install the gem. I feel like an idiot.. :)

    I’ll keep you posted on my results. Our state agency is currently a Java shop and it would be great to present them the slight possibility of deploying rails apps on our WebSphere servers. I’d much rather do development using Rails :)

  11. Avatar Jonathan Bartlett said 7 days later:

    One thing you should mention is that warbler should be installed from JRuby and not regular ruby.

  12. Avatar Jonathan Bartlett said 7 days later:

    One other thing -- I don’t know if this is a configuration setting or something w/ Jruby itself. When I use ActiveRecord-jdbc to connect to a JNDI datasource, on every page access it gives me a warning that it is closing a connection for me and shaming me for not doing it myself (not to mention throwing a stacktrace).

    I’m deploying via JBoss, if that matters.

    Here’s an example log message:

    18:29:42,339 INFO  [CachedConnectionManager] Closing a connection for you.  Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@add4cdjava.lang.Throwable: STACKTRACE
            at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:290)
    ..several hundred more lines...
  13. Avatar Stéphane Boulanger said 9 days later:

    @Nick: It´s in your mailbox!

    @Jonathan: I installed warbler into my regular ruby installation. Works (now) without problems.