JRuby + OpenURI + HTTPS的问题

时间:2012-04-21 11:45:38

标签: jruby

我在使用JRuby,Open URI和JRuby-OSSL编写非常简单的程序时遇到问题。

我使用:

安装了JRuby-OSSL gem
gem install jruby-openssl

并下载了最新的jruby-complete jar(1.6.7)。

我有简单的脚本test.rb:

require 'jruby/openssl/gem_only'
require 'open-uri'
open('https://google.com')

当我像这样运行时:

java -jar jruby-complete-1.6.7.jar test.rb

我明白了:

NameError: uninitialized constant Net::HTTP::OpenSSL
  const_missing at org/jruby/RubyModule.java:2642
       use_ssl= at file:/Users/mislocin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/net/https.rb:124
      open_http at file:/Users/mislocin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/open-uri.rb:231
    buffer_open at file:/Users/mislocin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/open-uri.rb:616
      open_loop at file:/Users/mislocin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/open-uri.rb:164
          catch at org/jruby/RubyKernel.java:1183
      open_loop at file:/Users/mislocin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/open-uri.rb:162
       open_uri at file:/Users/mislocin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/open-uri.rb:132
           open at file:/Users/mislocin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/open-uri.rb:518
           open at file:/Users/mislocin/.m2/repository/org/jruby/jruby-complete/1.6.7/jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/open-uri.rb:30
         (root) at test.rb:4

我很确定我错过了一些细节,感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

请尝试 openssl

require 'openssl'
require 'open-uri'
open('https://google.com')

但当然这可能不会解决你的问题。 你在jruby宝石中gem install jruby-openssl,但不是使用jruby而是直接调用java - 你不应该依赖它来根据你的ENV变量来解析宝石。

您还应该期望SSLError,因为您尚未将其配置为忽略证书验证,以下是如何获取 https:// URI的示例:https://gist.github.com/1361989 < / p>

答案 1 :(得分:-1)

好的,找到了我的错误。

错误地,我将GEM_HOME变量配置为指向我的gem repo而不是GEM_PATH。配置GEM_PATH环境变量后,一切正常。