Java System Properties
Quick Reference Guide


http.proxyHost Java System Property

The http.proxyHost java system property specifies the hostname or IP address of the proxy server used for HTTP connections.

Default Value

Not set by default. When not set, HTTP connections are made directly, without a proxy (unless java.net.useSystemProxies is enabled).

Overview of http.proxyHost

The 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.proxyHost does not apply to HTTPS URLs

The https protocol handler uses its own https.proxyHost and https.proxyPort system properties (where the default port is 443). If you need to proxy both HTTP and HTTPS traffic, you must set both sets of properties.

Example

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.

Related Properties

Other Networking System Properties

Here are some other networking Java system properties:

References

Supported Since

Java has supported the http.proxyHost system property since at least Java 1.4.

Setting http.proxyHost on Startup

You 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

Setting / Reading http.proxyHost at Runtime

You 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 setProperty may 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");
}