I've added some external jars to my CLASSPATH by adding this in config/application.rb
:
require 'java'
$CLASSPATH << "#{File.dirname(__FILE__)}/../backend/src/"
Dir["#{File.dirname(__FILE__)}/../backend/lib/*.jar"].each do |jar|
require jar
end
This works fine when running Rails using rails server
. The jars from the CLASSPATH are loaded. However, when running rake
the classpath is not set. How can I set it? In particular, I need to set it before loading my gems, since I use the JRClj gem, which relies on already having clojure.jar in my CLASSPATH.
(Oh, I also tried putting the code in environment.rb; didn't help)
By "not work", I mean:
$ rake rspec --trace
rake aborted!
No such file to load -- /MY_CURRENT_WORKING_DIRECTORY/clojure.lang.RT
org/jruby/RubyKernel.java:1063:in `load'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/lib/rake/default_loader.rb:6:in `load'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/lib/rake/application.rb:569:in `load_imports'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/lib/rake/application.rb:508:in `raw_load_rakefile'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `load_rakefile'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `run'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/gems/rake-0.9.2.2/bin/rake:33:in `(root)'
org/jruby/RubyKernel.java:1063:in `load'
/Users/pbiggar/.rvm/gems/jruby-1.6.5@jruby-clojure-combination/bin/rake:19:in `(root)'
This happened because a gem I was using used import
instead of java_import
, hitting JRUBY bug 3797. More detail in: JRuby: import vs include vs java_import vs include_class.
The code in the question is correct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With