开发者

require jruby seems to work and fail simultaneously

开发者 https://www.devze.com 2023-01-15 03:38 出处:网络
John-Breedloves-Mac-mini:~ john_breedlove$ irb >> require \'jruby\' => true >> require \'zxing\'
John-Breedloves-Mac-mini:~ john_breedlove$ irb
>> require 'jruby'
=> true
>> require 'zxing'
RuntimeError: ZXing requir开发者_如何学Goes 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
>> 

How is this possible?

Further, how would I write that in a ruby script, though? I have a file I want to execute called test.rb, which contains the following:

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

I am executing it from the command-line like so:

ruby test.rb

In this context, how do I include java? Or is this even possible?


You are using the JRuby gem, rather than the JRuby itself.

JRuby (which ZXing is checking on line 1) is a module that gets defined only after you require 'java' in JRuby.

This should be clearly stated in ZXing's documentation, but it doesn't seem to be.

Here's the test output when I run the following from cloned ZXing source code:

$ 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
0

精彩评论

暂无评论...
验证码 换一张
取 消