Installing RJB on Windows 7 (32bit) w/ MinGW

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

Ruby 1.9.2 – Rails 3 – Sqlite3 – RJB 1.3.4 on Windows 7 (32bit) w/o VC

Ruby

Download Ruby Windows Installer from http://rubyinstaller.org/downloads/, and run it.

RubyGems

Download and install RubyGems. Ruby 1.9.2 ships with rubygems 1.3.7. You might want to run

gem update --system

to update to rubygems 1.4.2 (latest at the time); Forget it for now (if you do not have much time to kill), coz rubygems bugs itself from doing so. There was a bug, and it got fixed at least with Ruby 1.9.2-290p (tested to upgrade gems to 1.8.6). To see what gems you have now, do

gem list --local

To update existing gems:

gem update

To remove old versions of gems: (be careful with the prompt for dependencies though, or do a “dry” run first)

gem cleanup -v

Rails

Install Rails:

gem install rails

Or a prerelease version:

gem install rails --pre

Probably, you will encounter some ri/rdoc related errors. Just ignore them.

Database

Install sqlite3 for instance:

gem install sqlite3

Note that sqlite3-ruby is obsolete. Do not forget to put the dll file (downloadable here for sqlite3.7.3) into your Ruby bin directory (“C:\Ruby\bin” by default). A download link for the dll file should be provided after installation. Just optionally do

bundle install

Test Your Server

Let’s do a test run. Create a test app

rails new test0

Start the server

cd test0
rails s

Go to http://localhost:3000/ and bang!

RJB (Ruby Java Bridge)

Use Rjb for … almost anything!
Suppose you already have JDK installed, and have JAVA_HOME correctly set (e.g., “C:\Program Files\Java\jdk1.6.0_23”). It seems no need to set environment variable “LD_LIBRARY_PATH = Path-to-your-JDK\jre\lib\i386” as suggested on Rjb’s webpage.

gem install rjb

Got an error as below?

jniwrap.h:24:19: error: 'long long long' is too long for GCC

Then see this post for a workaround; and do not try the following please (unless you have VC in the very beginning)

gem install rjb --platform x86-mswin32

With option “–platform x86-mswin32”, it may go through the installation without complaints, but later it will refuse to work and pop up error windows. That might be because some of the bins of rjb’s dependencies are built with mingw, rather than VC.