2011-01-30 30 views

回答

3

要通過JRuby傳遞JVM標誌,請使用-J...。在這種情況下:

jruby -J-Dhttp.proxyHost=foo -J-Dhttp.proxyPort=1234 -J-Dhttp.nonProxyHosts="*.bar.com" ... 

這在JRuby的幫助文本中有解釋。

-J[java option] pass an option on to the JVM (e.g. -J-Xmx512m) 
       use --properties to list JRuby properties 
       run 'java -help' for a list of other Java options 
+0

確實會將標誌傳遞給JVM,但Ruby的Net :: HTTPClient不會將它們帶入帳戶... – 2011-01-31 20:52:11

1

我有同樣的問題。我發現java或net :: http不遵守nonProxyHosts選項。解決此問題的最佳方法是修改ENV_JAVA設置以解決此問題。

用我走上確保nonProxyHosts的步驟有以下幾條:

1) JAVA_OPTS="-Dhttp.proxyHost=192*** -Dhttp.proxyPort=1234 -Dhttp.nonProxyHosts=local|127.0.0.1" 
OR 
1) JRUBY_OPTS="-J-Dhttp.proxyHost=192*** -J-Dhttp.proxyPort=1234 -J-Dhttp.nonProxyHosts=local|127.0.0.1" 

記住,至少在java1.7的nonProxyHosts不應該有報價看here

現在我發現net :: http或java本身實際上並不尊重nonProxyHosts選項。

但是你可以解決這個做JRuby中

a = URI("http://someurl") 
Net::HTTP.new(a).proxy?.should == true 
regex = /$#{ENV_JAVA["http.nonProxyHosts"]}/ #dollar needed to behave as expected 
if a.hostname.match(regex) 
    ENV_JAVA["http.proxyHost"]=nil 
end 
Net::HTTP.new(a).proxy?.should == false 

希望有所幫助以下。