how to have both Ruby and JRuby on windows ?

I have been having this problem on windows 7 where I have installed
JRuby, sometimes when I try to install a regular Ruby gem instead of
something for JRuby I get an error message that seems to indicate it
thinks it's for JRuby ..

Below is an example. If I was going to install the gem to JRuby I
would type
jruby -S gem install watir --no-ri --no-rdoc, but I tried to install
it to the other Ruby:

gem install watir --no-ri --no-rdoc

C:\Users\lguild\Downloads\devkit>gem install watir --no-ri --no-rdoc
Building native extensions. This could take a while...
ERROR: Error installing watir:
        ERROR: Failed to build gem native extension.

        c:/jruby-1.6.7/bin/jruby.exe extconf.rb
WARNING: JRuby does not support native extensions or the `mkmf'
library very wel
l.
Check http://kenai.com/projects/jruby/pages/Home for alternatives.
checking for strncpy_s()... IOError: Cannot run program "cc" (in
directory "C:\j
ruby-1.6.7\lib\ruby\gems\1.8\gems\win32-api-1.4.8\ext"): CreateProcess
error=2,
The system cannot find the file specified
         popen at org/jruby/RubyIO.java:3613
        xpopen at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:323
          open at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:260
        xpopen at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:316
     egrep_cpp at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:538
     have_func at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:758
  checking_for at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:652
      postpone at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:286
          open at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:260
      postpone at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:286
          open at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:260
      postpone at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:282
  checking_for at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:651
     have_func at c:/jruby-1.6.7/lib/ruby/site_ruby/shared/mkmf.rb:755
        (root) at extconf.rb:9
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=c:/jruby-1.6.7/bin/jruby

Gem files will remain installed in c:/jruby-1.6.7/lib/ruby/gems/1.8/
gems/win32-a
pi-1.4.8 for inspection.
Results logged to c:/jruby-1.6.7/lib/ruby/gems/1.8/gems/win32-
api-1.4.8/ext/gem_
make.out

C:\Users\lguild\Downloads\devkit>

The error, while mixed in the backtrace seems clear to me: the usage of native extensions © with JRuby is not recommended.

Also, it is failing to find a suitable compiler (“cc”).

If you still want to use JRuby, probably you should want to obtain a compiler for it. I heard that someone managed to use RubyInstaller DevKit with it, but I haven’t tried it out.

http://jonforums.github.com/ruby/2010/11/30/devkit-jruby-c-extensions.html

If your version of JRuby is newer than the one indicated there, perhaps you don’t need to compile JRuby yourself.

YMMV specially considering win32-api gems are not suitable for JRuby. Developers are working on port it to use FFI instead. You can also reach the Watir guys to figure out alternatives.

Hope that helps

I got it to work using the pic gem, I was trying to install watir on
my regular ruby and not jruby. Even though the error said jruby, I did
not invoke jruby gem.

If all the output including this part:

c:/jruby-1.6.7/bin/jruby.exe extconf.rb

Mentions JRuby, then you’re using JRuby :stuck_out_tongue:

Check your PATH, perhaps both JRuby and normal Ruby installation in your system are conflicting.