The error remains in RJB 1.3.7 and the solution should work with later rubygems versions.
Environment
gem env
Gives the RubyGems environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-12-25 patchlevel 136) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby192/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: C:/Ruby192/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby192/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
Try Installing Rjb
Set environment variable “JAVA_HOME” to JDK’s home directory. If you do not have VC (which I dislike for no reasons) on your Windows box, as mentioned in an earlier post, you will probably encounter the following error message
ERROR: Error installing rjb: ERROR: Failed to build gem native extension.
after running
gem install rjb
Do not try alternatively, using option “–platform x86-mswin32,” which requires VC for rjb to function correctly.
Then you can find the following if you endeavor to see between the dreadful lines:
In file included from load.c:31:0: jniwrap.h:24:19: error: 'long long long' is too long for GCC
Understand the Error Message
Open file “jniwrap.h” in “Path-to-your-rjb-1.3.4-Source\ext” where “Path-to-your-rjb-1.3.4-Source” is the rjb directory created by rubygems. It should look like “C:\Ruby192\lib\ruby\gems\1.9.1\gems\rjb-1.3.4.” Then locate the following line of code
typedef long long __int64;
That is the source of the error. As to 64-bit integer types, it seems that neither “__int64″ nor “long long” is a standard way for C++ compilers, while C99 supports “long long”.
Solution
In the file “jniwrap.h”, simply comment out this line or replace it with the following line should do the trick
typedef long long long64;
You will need MinGW installed for recompiling rjb. (Guess Cygwin should serve this purpose too.) Get automated installer for MinGW and MSYS from here. Then recompile rjb manually under directory “Path-to-your-rjb-1.3.4-Source/ext”:
cd "Path-to-your-rjb-1.3.4-Source/ext" make make all make install
cd .. gem spec ../../cache/rjb-1.3.4.gem --ruby > ../../specifications/rjb-1.3.4.gemspec
It may still cry a bit with the following warning. Well, just let it go.
WARNING: File 'C:/Ruby192/lib/ruby/gems/1.9.1/specifications/rjb-1.3.4.gemspec' does not evaluate to a gem specification
You can see that rjb-1.3.4 is now listed in the local gem list by doing
gem list --local
Test
Run all the tests and samples provided by rjb-1.3.4. It should all go through
cd test ruby test.rb ruby gctest.rb ruby exttest.rb cd ../samples ruby filechooser.rb
Say hello to Rjb? Save the following as hellorjb.rb
require 'rjb'
out = Rjb::import('java.lang.System').out
out.print('Hello Rjb from ')
p out._classname
Just run it
ruby hellorjb.rb
My environment is as following
Windows 7 Professional 64-bit
ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
RJB 1.3.9
I did a gem install rjb and it was succefully installed. In irb
require ‘rjb’
returns true
but when I try to do a Rjb::load(..) it throws
RuntimeError: can’t create Java VM
I have my JAVA_HOME set properly. In irb when i do ENV['JAVA_HOME'] it gives me
=> “C:\\Program Files\\Java\\jdk1.6.0_31″
Am not sue what am I doing wrong. I tried almost everything that’s beeing suggested in various forums. I’ve been pulling my hair out since last 2 days…any kinda help would be greatly appreciated.
Could you do in command line: ruby -d -rubygems -rrjb -e ‘Rjb::load’
and post the output?
Make sure you use Rjb::load in the correct way, and maybe you can try adding ['-Xmx1000M'] and ['-Xms500M'] as input parameters of Rjb::load.
Hi Cass,
We are facing the same issue, and the result of ruby -d -rubygems -rrjb -e ‘Rjb::load’ is
Exception `LoadError’ at C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems.rb:1273 -
cannot load such file — rubygems/defaults/ruby
Exception `LoadError’ at C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_req
uire.rb:36 – cannot load such file — rjb
Exception `DL::DLError’ at -e:1 – No such file or directory
Exception `DL::DLError’ at -e:1 – No such file or directory
Exception `RuntimeError’ at -e:1 – can’t create Java VM
-e:1:in `load’: can’t create Java VM (RuntimeError)
from -e:1:in `’
Thanks in advance