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


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
Comments:

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

Posted by Eric Berry on July 31, 2009 at 12:57 AM PDT #

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

Posted by Gary S. Weaver on July 31, 2009 at 03:09 AM PDT #

wow, very nice and incredible post.

http://www.johnvcaruana.com/

Posted by company formation malta on August 02, 2009 at 04:15 AM PDT #

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

Posted by web hosting on August 03, 2009 at 05:05 PM PDT #

[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...

Posted by Arun Gupta's Blog on August 11, 2009 at 11:11 PM PDT #

[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...

Posted by Arun Gupta's Blog on August 12, 2009 at 02:15 AM PDT #

Great..very nice and incredible post about GlassFish.
i visited many blogs but couldn't find
such valuable info. i will definetly add
this to my blogroll.

Posted by Ohio SEO on August 23, 2009 at 09:20 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today