我们已经使用 warbler (1.2.1) 和 JRuby (1.5.6) 在 Tomcat7 服务器上运行 Rails (2.2.2) 应用程序,但是由于我们想要简化到多台机器的部署,我们想要运行 rake 任务,之类db:migrate
的,在tomcat WEB-INF 位置下。我们已经打包了 db 文件夹以及所有迁移。
我们在网上看到推荐的一种方法不起作用:
java -jar lib/jruby-core-1.5.6.jar -S $JRUBY_HOME/bin/rake db:migrate RAILS_ENV=staging
/var/lib/jruby/bin/rake:9:in `require': no such file to load -- rubygems (LoadError)
from /var/lib/jruby/bin/rake:9
添加到 ENV 后:
GEM_HOME=$JRUBY_HOME/lib/ruby/gems/1.8
RUBYLIB=$JRUBY_HOME/lib/ruby/site_ruby/1.8
相同的命令给出:
/var/lib/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:32 warning: already initialized constant RAKEVERSION
/var/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require': no such file to load -- fileutils (LoadError)
from /var/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /var/lib/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:35
from /var/lib/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:31:in `require'
from /var/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /var/lib/jruby-1.5.6/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:29
from /var/lib/jruby-1.5.6/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:19:in `load'
from /var/lib/jruby/bin/rake:19
如果我只是运行:
jruby -S $JRUBY_HOME/bin/rake db:migrate RAILS_ENV=staging
我收到大量由供应商化的 gem 导致的 gem 错误调用堆栈。(OutOfMemoryError、NUllPointerException 等。这在运行之间实际上并不一致)。
这个问题(How do I run rake rake tasks in a rails app that is service by tomcat with jruby war deployment?)也没有任何问题。任何建议表示赞赏。
干杯。