Skip to content


Fix Gem.ruby singleton method on Windows #1448

merged 1 commit into from

2 participants


This issue was identified when trying to install the murmurhash3 gem, which includes native extensions, on the Windows platform using the jruby-complete JAR file as the executable. This generated an error message as follows:

C:\temp\JRuby_Test>set GEM_HOME=C:\temp\JRuby_Test\vendor\
C:\temp\JRuby_Test>set GEM_PATH=C:\temp\JRuby_Test\vendor\
C:\temp\JRuby_Test>java -jar C:\temp\JRuby_Test\jruby-complete-1.7.10.jar -S gem install murmurhash3
Building native extensions.  This could take a while...
ERROR:  Error installing murmurhash3:
        ERROR: Failed to build gem native extension.

    java -jar /C:/temp/JRuby_Test/jruby-complete-1.7.10.jar extconf.rb
Error: Unable to access jarfile /C:/temp/JRuby_Test/jruby-complete-1.7.10.jar

Gem files will remain installed in C:/temp/JRuby_Test/vendor/gems/murmurhash3-0.1.4 for inspection.
Results logged to C:/temp/JRuby_Test/vendor/gems/murmurhash3-0.1.4/ext/murmurhash3/gem_make.out

After digging in a bit, it looked like the problem was that there was an extraneous slash at the beginning of the result of the Gem.ruby singleton method call, causing the command to come out as /C:/... instead of just C:/...

I figured while I was in there, I'd extract the Gem.jar_path method and document what it's doing since it wasn't obvious to me at first glance what the "jarred_path" input string was going to look like.

Full Disclosure: I didn't run all the unit tests myself to make sure things don't break because I don't have the whole JRuby development environment set up on my machine. I did, however, manually test the specific behavior related to this change on Windows 7 using both the system-installed jruby.exe and the jruby-complete.jar file, and also on CentOS 6.5.

JRuby Team member

I am going to follow this up with a change to only use your logic when on Windows.

@enebo enebo merged commit beb7cfe into jruby:master

1 check failed

Details default The Travis CI build failed
@enebo enebo added a commit that referenced this pull request
@enebo enebo Follow-up to pr #1448 to only use driveletter logic if actually runni…
…ng on windows
@enebo enebo added a commit that referenced this pull request
@enebo enebo Follow-up to pr #1448 to only use driveletter logic if actually runni…
…ng on windows
JRuby Team member

Ah yeah that might be. In the case of cygwin I think you will see unix style paths right? c:/ will not show up unless it is mount'd but I think that would need to be a user-provided path perhaps? Well I guess we will see...

@GregMefford GregMefford deleted the GregMefford:patch-2 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 27, 2014
  1. @GregMefford
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 3 deletions.
  1. +17 −3 lib/ruby/shared/rubygems/defaults/jruby.rb
20 lib/ruby/shared/rubygems/defaults/jruby.rb
@@ -11,15 +11,29 @@ class << self
alias_method :original_ruby, :ruby
def ruby
ruby_path = original_ruby
- if jarred_path?(ruby_path)
- ruby_path = "java -jar #{ruby_path.sub(/^file:/,"").sub(/!.*/,"")}"
- end
+ ruby_path = "java -jar #{jar_path(ruby_path)}" if jarred_path?(ruby_path)
def jarred_path?(p)
p =~ /^file:/
+ # A jar path looks like this on non-Windows platforms:
+ # file:/path/to/file.jar!/path/within/jar/to/file.txt
+ # and like this on Windows:
+ # file:/C:/path/to/file.jar!/path/within/jar/to/file.txt
+ #
+ # This method returns:
+ # /path/to/file.jar
+ # or
+ # C:/path/to/file.jar
+ # as appropriate.
+ def jar_path(p)
+ path = p.sub(/^file:/, "").sub(/!.*/, "")
+ path = path.sub(/^\//, "") if path =~ /^\/[A-Za-z]:/
+ path
+ end
# Default home directory path to be used if an alternate value is not
Something went wrong with that request. Please try again.