Tuesday, January 01, 2008

JRuby .war packaging for Rails 2.0

I have been hacking on JRuby a bit lately.

I set out to deploy a Ruby on Rails 2.0 application to Tomcat 6 on Monday and it was harder than it should have been.

Some of my angst was no doubt the fact that I'm a newbie, but in case it helps anyone, here are the key bits that made it work for me.

I started with using the Goldspike .war generator. It worked, but was a little clunky.

So then I tried Nick Sieger's Warbler which is much simpler & has more of a Ruby feel to it. I found myself down a rat hole, however in that the Warbler gem comes with JRuby 1.0.1 and that doesn't seem to work with Rails 2.0. If you try to run on it you will be greeted with something like:

INFO: Deploying web application archive your-app-name-here.war 
Exception in thread "ObjectPoolManager" java.lang.NoSuchMethodError: org.jruby.RubyHash.op_aset(Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRub
        at org.jruby.ext.openssl.X509Name.createX509Name(X509Name.java:98)
        at org.jruby.ext.openssl.X509.createX509(X509.java:40)

The documentation is a little bit sparse on this topic & I didn't stumble upon anything in my googling around. The fix is simple - you just have to use a compliant version of JRuby. 1.0.3 works. Here are the steps I took to fix it:

  • Download jruby-complete-1.0.3.jar
  • Replace the JRuby that Warbler uses - one approach is to figure out where Warbler lives (
    gem which warbler OR jruby -S gem which warbler
    ) and replace the default jruby (1.0.1) with 1.0.3

warbler war:debug prints a YAML dump of the current configuration
is definitely useful in tracking stuff down.

Anyway, Warbler is quite simple & useful as it should be.

What's not to like about:

gem install warbler 
warbler war 
warbler config
warbler war:clean 
and warble.rb (config file)?

Note that you can also run it directly under JRuby:

jruby -S gem install warbler
jruby warbler war
jruby warbler config
jruby warbler:clean

Warbler is very tidy. It put's all the generated bits in the tmp dir of your Rails app. This is opposed to Goldspike which puts it all in the WEB-INF dir in the root of your app.

Update I put some of this and more in the JRuby Wiki.


Anonymous said...

Thanks a lot.
That'll save me a lot of time !


jevy said...

Tricky. What version of jruby-openssl were you using? I've tried both 0.1 and 0.1.1 and still get this issue. I did try using jruby 1.0.3 with no avail. Any more ideas?

jevy said...

Aww shoot. Followed your instructions more carefully. We're all good now.

Thanks for posting your findings. No doubt saved me lots of work

Marc said...

Thanks for the post, will try going to jruby soon and I guess this will be of great help