OS X的System代理的JVM自动设置如何工作? [英] How does JVM automatic setting of OS X's System proxies work?
问题描述
我正在弄乱代理设置和JVM.显然,OS X(在我的情况下为Maverics)是唯一在其上JVM(今天为1.8_92)自动应用系统首选项中设置的代理的系统.我测试过的任何其他系统(带有openbox的Arch Linux,没有Gnome/KDE,Windows 7,有一些最新的Debian版本)都没有这样做,有必要使用'-Djava.net.useSystemProxies' (适用于Windows)或使用"-Dhttp.proxyHost = ..."等明确设置代理.
我很确定应用了OS X系统代理,因为我在首选项中使用了特殊的标记"代理主机名.当我更改主机名时,JVM会将其代理设置更改为新的主机名(不过,我需要重新启动JVM,但是在JVM运行时它不会更改,但是可以).
我发现这种行为很酷(显然,代理仅在OS X上可以立即使用,在我使用其他系统遇到很多问题后,它可以刷新),但是似乎没有任何地方对此进行记录.
有人能证明神奇的是OS X上的JVM吗?它在哪里发生,由谁发生?我可以想象有多种方法可以实现这一目标:Mac的JVM可能很聪明,并且知道如何查找OS X的代理设置,或者每当网络设置发生变化时都可能写入一些配置文件,而JVM可以在启动时简单地读取它,或...很多选项,但是实际上如何工作?
有一个调用向下向下,该条件有条件地包含在MACOSX
中,该MACOSX
调用 System.c
,如果找到代理信息,则设置标准Java系统属性http.proxyPort
等. /p>
所以调用堆栈是:
-
Java_java_lang_System_initProperties
-
GetJavaProperties
-
setProxyProperties
-
SCDynamicStoreCopyProxies
<-OSX特定调用
如果上面的命令返回了某些内容,则紧跟在initProperties
方法中的PUTPROP
.
I'm messing around with proxy settings and the JVM. Apparently, OS X (Maverics in my case) is the only system on which the JVM (1.8_92 as of today) automagically applies whatever proxies are set in system preferences. Any other systems I tested it with (Arch Linux with openbox, no Gnome/KDE, Windows 7, some up-to-date Debian version) don't do that, it is either necessary to use '-Djava.net.useSystemProxies' (works on Windows), or explicitly set the proxies using '-Dhttp.proxyHost=...' etc.
I'm pretty sure OS X system proxies are applied, as I used a special 'marker' proxy host name in the preferences; when I change the host name, the JVM changes its proxy settings to the new host name (I need to restart the JVM, though, it doesn't change while the JVM is running, but that's OK).
I find this behavior cool (apparently, proxies just work out of the box with OS X, which is refreshing after tons of issues I had with other systems), but it seems to not be documented anywhere.
Can someone confirm that it's the JVM on OS X who does the magic? And where does it happen and by whom? I could imagine multiple ways of achieving this: the JVM for Macs could be smart and know how to look up OS X's proxy settings, or there could be some config file written whenever network settings change, and the JVM could simply read it at startup, or ... Many options, but how does it actually work?
There's a call to GetJavaProperties in libjava
which is implementation dependent; Mac OSX shares the general Unix implementation. This is used to set up any system properties such that they are then stamped on the general Java properties such as the file system's default encoding and so forth.
There's a bit down the bottom that is conditionally included for MACOSX
that calls setProxyProperties
which performs the proxy lookup using the OSX standard System Configuration framework.
Once the system proxy information is known it gets passed back up through the call chain into System.c
that says if the proxy information is found the standard Java system properties http.proxyPort
etc. are set.
So the call stack is:
Java_java_lang_System_initProperties
GetJavaProperties
setProxyProperties
SCDynamicStoreCopyProxies
<- the OSX specific call
Followed by the PUTPROP
in the initProperties
method if the above returns something.
这篇关于OS X的System代理的JVM自动设置如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!