'-Djava.net.useSystemProxies=true doesn't work in linux
I have a java application running in a linux environment. The environment has a http proxy server set using HTTP_PROXY
and HTTPS_PROXY
environment variables.
My java application needs to use a REST API, so I added the VM arg below to use the system proxy.
-Djava.net.useSystemProxies=true
But the java application disregards the proxy and tries to connect to the url directly.
However, if I use below VM args, it works properly.
-Dhttp.proxyHost=<host> -Dhttp.proxyPort=<port> -Dhttps.proxyHost=<host> -Dhttps.proxyPort=<port>
For me, using -Djava.net.useSystemProxies=true
is desirable since I don't have to change the command I use to run the java application when the proxy server is changed.
Any idea why -Djava.net.useSystemProxies=true
is not working?
Solution 1:[1]
In the documentation it states:
java.net.useSystemProxies (default: false)
On recent Windows systems and on Gnome 2.x systems it is possible to tell the java.net stack, setting this property to true, to use the system proxy settings (both these systems let you set proxies globally through their user interface). Note that this property is checked only once at startup.
So if you're not using gnome then this is unsupported. Something about how they are accessing properties from the looks of it.
How do I set the proxy to be used by the JVM
You may need to set proxy settings by hand. this bugreport on an unrelated project suggests that proxyhost/proxyport (see How do I set proxy to be used by the JVM) is a valid alternative.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Joeblade |