JRuby on Rails:将文件夹添加到类路径

发布于 2024-09-08 13:54:14 字数 1231 浏览 2 评论 0原文

我正在尝试将整个文件夹添加到我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流心雨 2024-09-15 13:54:14

首先需要java。这就是 $CLASSPATH 变量生效的原因。

include Java
$CLASSPATH << "your/folder"

在 JRuby 1.0 之前的版本中,您需要使用 require 'java' 来代替,但在现代 JRuby 中,这种方式默默地不起作用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文