Using a Proxy Server with Java
Category : How-to
Java applications can use a proxy server for making HTTP/ HTTPS connections to the internet by adding additional arguments to the startup command. It’s the JVM which is created with additional arguments to set up the JVM with the details required to proxy requests.
The following arguments are required:
- http.proxyHost – the host or IP address of the proxy server.
- ptty.proxyPort – is the port used by the proxy server. If this is not used the default of port 80 is assumed.
For example, to start the application myApplication.jar with a proxy server located at myproxyserver.local on port 8080:
java -jar myApplication.jar -Dhttp.proxyHost=myproxyserver.local -Dhttp.proxyPort=8080
You can also specify the nonProxyHosts to exclude specific domains from using the proxy server. The below will not proxy anything on mydomain.com, server.local or localhost.
-Dhttp.nonProxyHosts="*.mydomain.com|server.local|localhost"