July 31, 2009

TOTD #87: How to fix the error undefined method `new’ for “Rack::Lock”:String caused by Warbler/JRuby-Rack ?

Categories: rails, totd

If you are using Warbler to create a WAR file of your application and deploying on GlassFish or any other Servlet container, then you are likely seeing the following error during deployment:

[#|2009-07-30T15:29:50.788-0700|SEVERE|sun-appserver2.1|javax.enterprise.system.container.web|_ThreadID=17;
_ThreadName=httpWorkerThread-4848-0;_RequestID=1d7e8f18-1c9a-4924-bd0b-6a07eba425ba;|WebModule
[/session]unable to create shared application instance
org.jruby.rack.RackInitializationException: undefined method `new’ for “Rack::Lock”:String
        from /Users/arungupta/tools/glassfish/v2.1/glassfish/domains/domain1/applications/j2ee-modules/session/WEB-INF/gems/gems/actionpack-2.3.2/lib/
action_controller/middleware_stack.rb:116:in `inject’
        from /Users/arungupta/tools/glassfish/v2.1/glassfish/domains/domain1/applications/j2ee-modules/session/WEB-INF/gems/gems/actionpack-2.3.2/lib/
action_controller/middleware_stack.rb:116:in `build’
        from /Users/arungupta/tools/glassfish/v2.1/glassfish/domains/domain1/applications/j2ee-modules/session/WEB-INF/gems/gems/actionpack-2.3.2/lib/
action_controller/dispatcher.rb:82:in `initialize’

. . .

This is a known issue as reported at JRUBY-3789 and JRUBY_RACK-18.

As the bug report indicates, this is actually an issue with jruby-rack-0.9.4 and is fixed in jruby-rack-0.9.5. The 3-step workaround is described here and explained below for convenience:

  1. Do “warble war:clean” to clean up the .war file and staging area. This basically removes previous version of jruby-rack.jar.
  2. Download the latest jruby-rack-0.9.5 snapshot (complete list) and copy in the “lib” directory of your application.
  3. If “config/warble.rb” does not exist then generate it using “jruby -S config warble”. Edit “config/warble.rb” such that it looks like:
      # Additional Java .jar files to include. Note that if .jar files are placed
      # in lib (and not otherwise excluded) then they need not be mentioned here.
      # JRuby and JRuby-Rack are pre-loaded in this list. Be sure to include your
      # own versions if you directly set the value
      # config.java_libs += FileList["lib/java/*.jar"]
      config.java_libs.delete_if {|f| f =~ /jruby-rack/ }
      config.java_libs += FileList["lib/jruby-rack*.jar"]

    This will pack jruby-rack-0.9.5 snapshot instead of the one bundled with Warbler.

    Now warbler 1.0.0 bundles “jruby-complete-1.3.0RC1.jar”. Optionally, you can also download the latest jruby-complete (jruby-complete-1.3.1.jar as of this writing) and copy in the “lib” directory of your application. In that case, modify the above fragment to:

      # Additional Java .jar files to include. Note that if .jar files are placed
      # in lib (and not otherwise excluded) then they need not be mentioned here.
      # JRuby and JRuby-Rack are pre-loaded in this list. Be sure to include your
      # own versions if you directly set the value
      # config.java_libs += FileList["lib/java/*.jar"]
      config.java_libs.delete_if {|f| f =~ /jruby-rack/ || f =~ /jruby-complete/ }
      config.java_libs += FileList["lib/jruby-complete*.jar"]
      config.java_libs += FileList["lib/jruby-rack*.jar"]

    This packs the “jruby-complete-1.3.1.jar” in your .war file.

And now follow your regular procedure of creating the .war file using “jruby -S warble” and happily deploy your Rails/Sintara/Merb applications on GlassFish.

There are several users who are already using Rails on GlassFish in production environment and they are listed at rubyonrails+glassfish+stories. Drop a comment on this blog if you are using it too :)

Technorati: jruby rack glassfish war servlet rubyonrails

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • E-mail this story to a friend!
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. TOTD #73: JRuby and GlassFish Integration Test #4: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v2 + Warbler
  2. GlassFish + JRuby + JRuby-Rack + Warbler = Blog Deployment Platform
  3. WAR-based Packaging and Deployment of Rails on GlassFish – Goldspike, RailServlet, Warbler, Rack, …
  4. TOTD #72: JRuby and GlassFish Integration Test #3: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v3
  5. TOTD #14: How to generate JRuby-on-Rails Controller on Windows (#9893)

6 Comments »

  1. Great job on figuring this out. I’m glad you’re on top of things, Arun!

    Comment by Eric Berry — July 31, 2009 @ 7:57 am

  2. Arun,

    Glad to see that fix helped. Hope you had a good time at the house warming ceremony!

    Gary

    http://stufftohelpyouout.blogspot.com/2009/06/how-to-get-warbler-to-include-custom.html

    Comment by Gary S. Weaver — July 31, 2009 @ 10:09 am

  3. wow, very nice and incredible post.

    http://www.johnvcaruana.com/

    Comment by company formation malta — August 2, 2009 @ 11:15 am

  4. We at reliable hosts appreciate the
    knowledge the blog owner has about this topic.

    Comment by web hosting — August 4, 2009 @ 12:05 am

  5. [Trackback] The GlassFish High Availability allows to setup a cluster of GlassFish instances and achieve highly scalable architecture using in-memory session state replication. This cluster can be very easily created and tested using the "clusterjsp" sample bundl…

    Comment by Arun Gupta's Blog — August 12, 2009 @ 6:11 am

  6. [Trackback] The GlassFish High Availability allows to setup a cluster of GlassFish instances and achieve highly scalable architecture using in-memory session state replication. This cluster can be very easily created and tested using the "clusterjsp" sample bundl…

    Comment by Arun Gupta's Blog — August 12, 2009 @ 9:15 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress
8809 visits from Sep 11, 2009