5

我通过在 CLASSPATH 中添加了一些外部 jar config/application.rb

require 'java'
$CLASSPATH << "#{File.dirname(__FILE__)}/../backend/src/"
Dir["#{File.dirname(__FILE__)}/../backend/lib/*.jar"].each do |jar|
   require jar
end

这在使用rails server. 加载来自 CLASSPATH 的 jar。但是,在运行时rake未设置类路径。我该如何设置?特别是,我需要在加载我的 gem 之前设置它,因为我使用 JRClj gem,它依赖于我的 CLASSPATH 中已经有 clojure.jar。

(哦,我也尝试将代码放在 environment.rb 中;没有帮助)

我所说的“不工作”是指:

$ 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)'
4

1 回答 1

4

发生这种情况是因为我使用的 gemimport而不是java_importJRUBY错误 3797。更多细节在:JRuby:import vs include vs java_import vs include_class

问题中的代码是正确的。

于 2011-11-14T03:45:42.597 回答