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:
- Do “warble war:clean” to clean up the .war file and staging area. This basically removes previous version of jruby-rack.jar.
- Download the latest jruby-rack-0.9.5 snapshot (complete list) and copy in the “lib” directory of your application.
- 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