2

据我了解,gem 的文件夹结构应该有一个名为的文件夹lib,并且在该文件夹内有一个<gem-name>.rb文件。但是,当我使用jruby 1.6.8bundle install安装 jruby-openssl 时,我打开C:\jruby-1.6.8\lib\ruby\gems\1.8\gems\jruby-openssl-0.8.2并没有看到 rb 文件,而是看到了更多如下所示的子文件夹:

jruby-openssl-0.8.2\
+---lib\
|   +---1.8\
|   |   +---openssl\
|   |   +---openssl.rb
|   +---1.9\
|   |   +---openssl\
|   |   +---openssl.rb
|   +---ruby\
|   |   +---shared\
|   +---shared\
|       +---jopenssl\
|       +---openssl\
|       +---openssl.rb
+---test\
    +---java\

jruby-openssl 不遵循标准 gem 文件夹结构是否有原因?具体来说,我似乎在使用gem 'jruby-openssl'命令时遇到问题。gem如果jruby-openssl 文件夹位于 LOAD_PATH 中,该命令是否应该正确找到并加载 gem?



错误详情:

这是出现在C:\apachetomcat632\logs\MyWebapp.log

--- Backtrace
LoadError: OpenSSL::Cipher requires the jruby-openssl gem
            (root) at file:/C:/apachetomcat632/shared/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/jruby/openssl/autoloads/cipher.rb:8
  MessageEncryptor at file:/C:/apachetomcat632/shared/lib/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/jruby/openssl/autoloads/cipher.rb:24
     ActiveSupport at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/activesupport-3.2.11/lib/active_support/message_encryptor.rb:12
            (root) at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/activesupport-3.2.11/lib/active_support/message_encryptor.rb:4
           require at org/jruby/RubyKernel.java:1062
           require at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251
   load_dependency at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236
           require at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251
   eager_autoload! at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/activesupport-3.2.11/lib/active_support/message_encryptor.rb:43
              each at org/jruby/RubyArray.java:1620
   eager_autoload! at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/activesupport-3.2.11/lib/active_support/dependencies/autoload.rb:43
         Bootstrap at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/railties-3.2.11/lib/rails/application/bootstrap.rb:20
     instance_exec at org/jruby/RubyKernel.java:2091
               run at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/railties-3.2.11/lib/rails/initializable.rb:30
  run_initializers at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/railties-3.2.11/lib/rails/initializable.rb:55
              each at org/jruby/RubyArray.java:1620
  run_initializers at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/railties-3.2.11/lib/rails/initializable.rb:54
       initialize! at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/railties-3.2.11/lib/rails/application.rb:136
              send at org/jruby/RubyKernel.java:2105
    method_missing at file:C:/apachetomcat632/shared/lib/cfe-gems.jar!/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30
            (root) at C:/apachetomcat632/webapps/Bank62P/WEB-INF/rails/config/environment.rb:5
           require at org/jruby/RubyKernel.java:1062
  load_environment at C:/apachetomcat632/webapps/Bank62P/WEB-INF/rails/config/environment.rb:23
  load_environment at file:/C:/apachetomcat632/shared/lib/jruby-rack.jar!/jruby/rack/rails_booter.rb:65
            (root) at <script>:1

这是整个 cipher.rb 文件:

require 'rubygems'

# try to activate jruby-openssl gem for OpenSSL::SSL, raising error if gem not present
begin
  gem 'jruby-openssl'
  require 'openssl.rb'
rescue Gem::LoadError => e
  raise LoadError.new("OpenSSL::Cipher requires the jruby-openssl gem")
end
4

2 回答 2

2

要添加到 tadman 的答案,如果您查看 gemspec ( gems/1.8/specifications/jruby-openssl-0.8.2.gemspec),您会看到这一行:

s.require_paths = ["lib/shared"]

当您require 'openssl'在代码中时,它将加载shared目录中的代码。我相信该文件将决定是否加载 1.8 或 1.9 版本。

照这样说...

当我尝试require 'openssl'使用 0.8.2 时,出现错误:

LoadError: no such file to load -- openssl/dummy

当我使用最新的(0.8.8)时,它工作正常。尝试升级。

于 2013-05-13T16:14:20.473 回答
0

在 JRuby 1.7.0 版之前,对 1.9 的支持非常不完整,您最好使用 1.8 代码。这可能就是为什么需要该特定库的两个单独实现的原因。

像这样将它们捆绑在一起有点不寻常,通常 1.8 安装只会锁定到旧版本的 gem。JRuby 在这里提出了一个挑战,这看起来是一个相当合理的解决方案。

于 2013-05-13T15:39:46.503 回答