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:
cellpadding="2" cellspacing="2">
_ThreadName=httpWorkerThread-4848-0;_RequestID=1d7e8f18-1c9a-4924-bd0b-6a07eba425ba;|WebModule
[/session]unable to create shared application instance
org.jruby.rack.RackInitializationException: style="font-weight: bold;">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
href="http://jira.codehaus.org/browse/JRUBY-3789">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
href="http://stufftohelpyouout.blogspot.com/2009/06/how-to-get-warbler-to-include-custom.html">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
href="http://snapshots.repository.codehaus.org/org/jruby/rack/jruby-rack/0.9.5-SNAPSHOT/">jruby-rack-0.9.5
snapshot ( href="http://snapshots.repository.codehaus.org/org/jruby/rack/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:
style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
cellpadding="2" cellspacing="2">
# 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 ( href="http://dist.codehaus.org/jruby/1.3.1/jruby-complete-1.3.1.jar">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:
style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
cellpadding="2" cellspacing="2">
# 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/
href="http://blogs.sun.com/arungupta/entry/totd_80_sinatra_crud_application">Sintara/
href="http://blogs.sun.com/arungupta/entry/lotd_15_deploying_merb_application">Merb
applications on GlassFish.
There are several users who are already using Rails on GlassFish in
production environment and they are listed at
href="http://blogs.sun.com/arungupta/tags/rubyonrails+glassfish+stories">rubyonrails+glassfish+stories.
Drop a comment on this blog if you are using it too :)
Technorati: jruby
rack
href="http://technorati.com/tags/glassfish">glassfish
war
href="http://technorati.com/tags/servlet">servlet
href="http://technorati.com/tags/rubyonrails">rubyonrails
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 1330 reads





