JRuby on Rails:将文件夹添加到类路径
我正在尝试将整个文件夹添加到我的 Rails 应用程序的 JRuby 1.5 类路径中。 JRuby Wiki 建议如下:“...将 config 目录添加到 config/environment.rb
中的 JRuby 类路径:”
$CLASSPATH << "file:///#{File.expand_path(File.join(RAILS_ROOT, 'config'))}/"
这似乎不起作用为我。我将其放在 Rails::Initializer.run 块之前、之后还是内部并不重要。无论如何,我得到:
/home/sean/src/sbruby/seo/config/environment.rb:45:NoMethodError: undefined method `<<' for nil:NilClass
/home/sean/apps/jruby/jruby-1.5.0/lib/ruby/gems/1.8/gems/rails-2.3.7/lib/rails/backtrace_cleaner.rb:2:NameError: uninitialized constant ActiveSupport::BacktraceCleaner
/home/sean/apps/jruby/jruby-1.5.0/lib/ruby/gems/1.8/gems/rails-2.3.7/lib/console_with_helpers.rb:5:NameError: uninitialized constant ApplicationController
例如,我试图在 RAILS_ROOT
下添加一个名为 resources/foobar
的文件夹,因此我将以下内容添加到 environment.txt 中。 rb:
$CLASSPATH << "file:///#{File.expand_path(File.join(RAILS_ROOT, "resources", "foobar"))}/"
同样的错误。
使用 Rails 将文件夹添加到 JRuby 类路径的正确方法是什么?
I'm trying to add an entire folder to the JRuby 1.5 classpath for my Rails app. The JRuby Wiki suggests the following: "... add the config directory to the JRuby classpath in config/environment.rb
:"
$CLASSPATH << "file:///#{File.expand_path(File.join(RAILS_ROOT, 'config'))}/"
That doesn't seem to work for me. It doesn't matter whether I put that before, after or inside of the Rails::Initializer.run
block. No matter what, I get:
/home/sean/src/sbruby/seo/config/environment.rb:45:NoMethodError: undefined method `<<' for nil:NilClass
/home/sean/apps/jruby/jruby-1.5.0/lib/ruby/gems/1.8/gems/rails-2.3.7/lib/rails/backtrace_cleaner.rb:2:NameError: uninitialized constant ActiveSupport::BacktraceCleaner
/home/sean/apps/jruby/jruby-1.5.0/lib/ruby/gems/1.8/gems/rails-2.3.7/lib/console_with_helpers.rb:5:NameError: uninitialized constant ApplicationController
For example, I'm trying to add a folder under RAILS_ROOT
called resources/foobar
, so I added the following to environment.rb
:
$CLASSPATH << "file:///#{File.expand_path(File.join(RAILS_ROOT, "resources", "foobar"))}/"
Same error.
What is the right way to add a folder to the JRuby classpath with Rails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先需要java。这就是 $CLASSPATH 变量生效的原因。
在 JRuby 1.0 之前的版本中,您需要使用
require 'java'
来代替,但在现代 JRuby 中,这种方式默默地不起作用。Require java first. That's what makes the $CLASSPATH variable live.
In pre-1.0 versions of JRuby, you'd do
require 'java'
instead, but in modern JRuby that silently doesn't work.