为什么jruby-openssl gem有奇怪的文件夹结构?

时间:2013-05-13 15:34:04

标签: ruby gem jruby jruby-openssl

根据我的理解,gem的文件夹structer应该有一个名为lib的文件夹,在该文件夹中有一个<gem-name>.rb文件。但是,当我使用 jruby 1.6.8 并执行bundle 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'命令工作的问题。如果jruby-openssl文件夹在LOAD_PATH中,gem命令是否应该正确查找并加载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

2 个答案:

答案 0 :(得分: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版本。

据说......

当我尝试使用0.8.2 require 'openssl'时,我收到错误:

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

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

答案 1 :(得分:0)

在JRuby 1.7.0版之前,1.9支持是如此不完整以至于你最好使用1.8代码。这可能是为什么需要对该特定库进行两次单独的实现。

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