http.proxyPortThe 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.proxyPortdoes not apply to HTTPS URLsHTTPS connections use the
https.proxyHostandhttps.proxyPortsystem properties instead. The default value ofhttps.proxyPortis443.
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");
http.proxyHost - the hostname or address of the HTTP proxy server.http.nonProxyHosts - a | separated list of hosts that should be accessed directly, bypassing the proxy.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.proxyHosthttps.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.proxyPort system property since at least Java 1.4.
http.proxyPort on StartupYou 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
http.proxyPort at RuntimeYou 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
setPropertymay 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");
}