Not set by default. When not set, HTTP connections are made directly, without a proxy (unless java.net.useSystemProxies is enabled).
http.proxyHostThe http.proxyHost system property sets the hostname, or address, of the proxy server that the http protocol handler should use. It is typically used together with the http.proxyPort system property, which defaults to 80 when not specified.
The property is used by the default ProxySelector, so it applies to connections made with java.net.URL / HttpURLConnection, and also to the java.net.http.HttpClient (Java 11+) when no explicit proxy selector has been set on the client builder.
System properties are VM wide settings, so once a proxy has been set it will affect all HTTP connections made by all threads in the JVM.
Note:
http.proxyHostdoes not apply to HTTPS URLsThe
httpsprotocol handler uses its ownhttps.proxyHostandhttps.proxyPortsystem properties (where the default port is443). If you need to proxy both HTTP and HTTPS traffic, you must set both sets of properties.
java -Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts="localhost|*.example.com" -jar app.jar
In this example all HTTP connections will go through the proxy server at proxy.example.com on port 8080, except for connections to localhost or any host in the example.com domain.
http.proxyPort - the port number of the HTTP proxy server, default 80.http.nonProxyHosts - a | separated list of hosts that should be accessed directly, bypassing the proxy. The * wildcard can be used for pattern matching. In modern Java versions the default is localhost|127.*|[::1]. This list is also used for HTTPS connections.https.proxyHost and https.proxyPort - the proxy server used for HTTPS connections.java.net.useSystemProxies - use the operating system's proxy settings.Here are some other networking Java system properties:
com.sun.net.ssl.checkRevocationcom.sun.security.enableCRLDPhttp.agenthttp.keepAlivehttp.maxConnectionshttp.nonProxyHostshttp.proxyPorthttps.protocolshttps.proxyHosthttps.proxyPortjava.net.preferIPv4Stackjava.net.preferIPv6Addressesjava.net.useSystemProxiesjavax.net.debugjavax.net.ssl.trustStorejdk.http.maxHeaderSizejdk.net.hosts.filejdk.tls.client.protocolsjdk.tls.server.newSessionTicketCountjdk.crypto.disabledAlgorithmsjdk.tls.disabledAlgorithmsnetworkaddress.cache.negative.ttlnetworkaddress.cache.ttlocsp.enablesun.net.client.defaultConnectTimeoutsun.net.client.defaultReadTimeoutsun.net.inetaddr.ttlJava has supported the http.proxyHost system property since at least Java 1.4.
http.proxyHost on StartupYou can set the http.proxyHost java system property during startup of the java runtime using the -D command line argument:
java -Dhttp.proxyHost=proxy.example.com MyAppMain
You may also be able to specify http.proxyHost via the JAVA_TOOL_OPTIONS environment variable:
JAVA_TOOL_OPTIONS=-Dhttp.proxyHost=proxy.example.com
http.proxyHost at RuntimeYou can set http.proxyHost at runtime with the following Java code:
System.setProperty("http.proxyHost", "proxy.example.com");
WARNING: Depending on the property and JVM version using
setPropertymay or may not work if the JDK Java class that uses this variable has already been loaded. The value of the http.proxyHost system property may be cached within an internal private static variable of the implementing class.
To read the value of http.proxyHost at runtime, you can use this Java code:
String propertyValue = System.getProperty("http.proxyHost");
if (propertyValue != null) {
System.out.println("http.proxyHost = " + propertyValue);
} else {
System.out.println("http.proxyHost was null");
}