开发者

JRuby on Rails: Adding a folder to the classpath

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/j开发者_如何学Pythonruby/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?


Require java first. That's what makes the $CLASSPATH variable live.

include Java
$CLASSPATH << "your/folder"

In pre-1.0 versions of JRuby, you'd do require 'java' instead, but in modern JRuby that silently doesn't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜