Search code examples
javajrubyrequireirb

require 'java' fails in irb


I'm new to jruby and to irb and I seem to have an issue with requiring java. Here is what happens:

irb(main):001:0> require 'java'
LoadError: cannot load such file -- java
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from (irb):1
    from /usr/bin/irb:12:in `<main>'
irb(main):002:0> 

From other posts I saw the suggestion of requiring rubygems before requiring java but that did not seem to matter:

irb(main):003:0> require 'rubygems'
=> false
irb(main):004:0> require 'java'
LoadError: cannot load such file -- java
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from (irb):3
    from /usr/bin/irb:12:in `<main>'
irb(main):005:0> 

Can anyone point me in the right direction here?

btw java IS installed:

/usr/local/jruby-1.7.9/samples/jrubyc_java$ java -version
java version "1.7.0_85"
OpenJDK Runtime Environment (IcedTea 2.6.1) (7u85-2.6.1-5ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.85-b03, mixed mode)
/usr/local/jruby-1.7.9/samples/jrubyc_java$ 

A


Solution

  • you might have JRuby installed at /usr/local/jruby-1.7.9 but your GEM_HOME GEM_PATH variables seem to point to the system installed (MRI) Ruby: /usr/lib/ruby/1.9.1/rubygems try starting irb as jruby -S irb and/or unset those variables (or you might need to set them accordingly to point to the gem-home under the JRuby installation).