Ruby - 加载gems形成非默认目录

时间:2014-06-19 13:03:42

标签: ruby gem rubygems jruby

我正在尝试从非默认目录加载RubyGems,默认情况下(请在此处更正,如果我错了)在Gem.path数组中指定。我已经设法加载我在非默认目录('rubyzip')中安装的唯一宝石,但只有少数情况......

我正在使用 JRuby 1.7.12 Ruby 1.9.3

以下是我的测试结果:

从“E:/ rb / gems_”目录加载gem:

Gem.path
=> ["C:/Users/default/.gem/jruby/1.9", "file:/E:/rb/libraries/jruby.jar!/META-INF/jruby.home/lib/ruby/gems/shared"]
Gem.path[0] = "E:/rb/gems_"
=> "E:/rb/gems_"
require 'zip'
=> true

在上面的测试中,我用我的“E:/ rb / gems_”目录替换了与用户相关的默认gem路径,一切正常。

Gem.path.clear
=> []
Gem.path.unshift "E:/rb/gems_"
=> ["E:/rb/gems_"]
require 'zip'
=> true

同样,即使我清除整个数组并用我自己的条目替换它,一切都运行得很好。

从“E:/ rb / gems”目录加载gem(现在没有下划线。我测试了错误命名的可能性)

Gem.path.clear
=> []
Gem.path.unshift "E:/rb/gems"
=> ["E:/rb/gems"]
require 'zip'
=> true

此测试也成功完成。

这是最后一次测试:

Gem.path.clear
=> []
require 'zip'
LoadError: no such file to load -- zip
        from org/jruby/RubyKernel.java:1065:in `require'
        from file:/E:/rb/libraries/jruby.jar!/META-INF/jruby.home/lib/ruby/share
d/rubygems/core_ext/kernel_require.rb:55:in `require'
        from (irb):4:in `evaluate'
        from org/jruby/RubyKernel.java:1101:in `eval'
        from org/jruby/RubyKernel.java:1501:in `loop'
        from org/jruby/RubyKernel.java:1264:in `catch'
        from org/jruby/RubyKernel.java:1264:in `catch'
        from file:/E:/rb/libraries/jruby.jar!/META-INF/jruby.home/bin/jirb:13:in
 `(root)'
        from org/jruby/RubyKernel.java:1081:in `load'
        from file:/E:/rb/libraries/jruby.jar!/jruby/commands.rb:1:in `(root)'
        from jirb:1:in `(root)'
Gem.path
=> []
Gem.path.clear.unshift "E:/rb/gems"
=> ["E:/rb/gems"]
require 'zip'
LoadError: no such file to load -- zip
        from org/jruby/RubyKernel.java:1065:in `require'
        from file:/E:/rb/libraries/jruby.jar!/META-INF/jruby.home/lib/ruby/share
d/rubygems/core_ext/kernel_require.rb:55:in `require'
        from (irb):7:in `evaluate'
        from org/jruby/RubyKernel.java:1101:in `eval'
        from org/jruby/RubyKernel.java:1501:in `loop'
        from org/jruby/RubyKernel.java:1264:in `catch'
        from org/jruby/RubyKernel.java:1264:in `catch'
        from file:/E:/rb/libraries/jruby.jar!/META-INF/jruby.home/bin/jirb:13:in
 `(root)'
        from org/jruby/RubyKernel.java:1081:in `load'
        from file:/E:/rb/libraries/jruby.jar!/jruby/commands.rb:1:in `(root)'
        from jirb:1:in `(root)'
Gem.path
=> ["E:/rb/gems"]

这里有“有趣”的部分。当'zip'数组中没有条目时,我试图加载Gem.path文件,这显然是失败的,这当然不仅仅是很好的结果。但是,当我使用我的RubyZip gem填充数组中只有一个指向非默认目录的条目时,它再次失败!

我的问题是:为什么加载RubyGem的第二个失败失败了?我有什么东西可以俯瞰吗?这种方法是从非默认目录中加载gems,还是有更好的?

0 个答案:

没有答案