Though there seem to be a bunch of questions and answers related to setting the JAVA_HOME variable in Windows, I am not entirely sure where I am going wrong.
I've followed all sorts of different开发者_如何学JAVA instructions on setting the environment variable, and when I check the environment variable in ruby I get
c:\Ruby192>rib irb(main):001:0> puts ENV['JAVA_HOME'] "c:\progra~1\java\jdk1.6.0_20" => nil
So I have been interpreting this as the environment variable being set , as the path to my jdk is returned, but what is the 'nil'??
echo %JAVA_HOME%
also returns the path to my jdk.
When I run
gem install rjb
I get
extconf.rb:39:in '(main)': JAVA_HOME is not a directory. (RuntimeError)
When I look in the extconf.rb file, sure enough, I've got
javahome = ENV['JAVA_HOME'] if javahome.nil? && RUBY_PLATFORM =~ /darwin/ javahome = `/usr/libexec/java_home`.strip end unless javahome.nil? if javahome[0] == ?" && javahome[-1] == ?" javahome = javahome[1..-2] end raise "JAVA_HOME is not directory." unless File.directory?(javahome) pt = Path.new
So from what I can tell, either the nil means that JAVA_HOME isn't being found, or I'm not pointing it to the right path or something.
I've tried including the '\bin' to the end of the path, as some responses said that was necessary, but I get the same result.
Any suggestions?
The nil is just irb returning to you the result of evaluating your expression, which was puts ...
. Puts printed your expression, but the return value of puts is nil. It has nothing to do with the contents of ENV['JAVA_HOME']
. Nil just meant puts returned nil, which is perfectly normal. Try puts "hello"
, and you'll see the same thing.
If the exception indeed comes from the line in your extconf.rb paste. It means File.directory?(javahome)
returned false.
I would start by playing with that in irb. I.e. try:
File.directory?('c:\progra~1\java\jdk1.6.0_20')
...and see what you get. That path looks suspiciously like some sort of MSDOS wannabe shorthand. Maybe you want to replace it with the real thing like C:\Program Files\java\jdk1.6.0_20
, and see if File.directory?()
gets happier then.
Edit:
Also try dir %JAVA_HOME%
in your DOS prompt. Make sure you're actually pointing your JAVA_HOME to where it should be.
精彩评论