views:

40

answers:

2

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?

A: 

I think you need this in your environment.rb

ENV['CLASSPATH'] << ":#{File.expand_path(File.join(RAILS_ROOT, 'config'))}/"
bjg
+1  A: 

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

require 'java'
$CLASSPATH << "your/folder"
Nick Sieger
Awesome. That was what I was missing!
organicveggie
I updated the JRuby wiki as well to reflect that requirement. Thanks again.
organicveggie