要求jruby似乎同时工作和失败

时间:2010-09-03 01:39:59

标签: ruby jruby

John-Breedloves-Mac-mini:~ john_breedlove$ irb
>> require 'jruby'
=> true
>> require 'zxing'
RuntimeError: ZXing requires JRuby
 from /Library/Ruby/Gems/1.8/gems/zxing-0.1.1/lib/zxing.rb:1
 from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
 from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `require'
 from (irb):2
>> 

这怎么可能?

此外,我如何在ruby脚本中编写它? 我有一个我想要执行的文件名为test.rb,其中包含以下内容:

require 'rubygems'
require 'jruby'
require 'zxing'
ZXing.decode 'test.png'

我正在从命令行执行它,如下所示:

ruby test.rb

在这种情况下,我如何包含java?或者这甚至可能吗?

1 个答案:

答案 0 :(得分:1)

您使用的是JRuby gem,而不是JRuby本身。

JRuby(ZXing在第1行检查)是一个仅在JRuby中require 'java'之后定义的模块。

这应该在ZXing的文档中明确说明,但似乎不是。

以下是从克隆的ZXing源代码运行以下内容时的测试输出:

$ ruby -v -I lib -r zxing -e 'p 0'
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
./lib/zxing.rb:1: ZXing requires JRuby (RuntimeError)
$ jruby -I lib -r zxing -e 'p 0'
/Users/asari/Development/src/zxing.rb/lib/zxing.rb:1: ZXing requires JRuby (RuntimeError)
    from /Users/asari/Development/src/zxing.rb/lib/zxing.rb:1
    ...internal jruby stack elided...
    from (unknown).(unknown)(/Users/asari/Development/src/zxing.rb/lib/zxing.rb:1)
    from (unknown).(unknown)(:1)
$ jruby -r java -I lib -r zxing -e 'p 0'
0