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
>>
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 yourequire '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: