Java System Properties
Quick Reference Guide


http.proxyPort Java System Property

The http.proxyPort java system property specifies the port number of the proxy server used for HTTP connections.

Default Value

80

Overview of http.proxyPort

The http.proxyPort system property sets the port number of the proxy server that the http protocol handler should use. It has no effect on its own, a proxy is only used when the http.proxyHost system property is also set. If http.proxyHost is set but http.proxyPort is not, the default port 80 is used.

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.

Note: http.proxyPort does not apply to HTTPS URLs

HTTPS connections use the https.proxyHost and https.proxyPort system properties instead. The default value of https.proxyPort is 443.

Example

java -Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=8080 -jar app.jar

You can also set the proxy at runtime, but keep in mind that system properties are VM wide, so this will affect HTTP connections made by all threads:

System.setProperty("http.proxyHost", "proxy.example.com");
System.setProperty("http.proxyPort", "8080");

Related Properties

Other Networking System Properties

Here are some other networking Java system properties:

References

Supported Since

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

Setting http.proxyPort on Startup

You can set the http.proxyPort java system property during startup of the java runtime using the -D command line argument:

java -Dhttp.proxyPort=8080 MyAppMain

You may also be able to specify http.proxyPort via the JAVA_TOOL_OPTIONS environment variable:

JAVA_TOOL_OPTIONS=-Dhttp.proxyPort=8080

Setting / Reading http.proxyPort at Runtime

You can set http.proxyPort at runtime with the following Java code:

System.setProperty("http.proxyPort", "8080");

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.proxyPort system property may be cached within an internal private static variable of the implementing class.

To read the value of http.proxyPort at runtime, you can use this Java code:

String propertyValue = System.getProperty("http.proxyPort");
if (propertyValue != null) {
    System.out.println("http.proxyPort = " + propertyValue);
} else {
    System.out.println("http.proxyPort was null");
}