Setting http Proxy for Java Application

There are 2 main ways to set/configure http proxy in your java application.

  • As a command line option when invoking the VM
  • Using the System.setProperty(String, String) in your code

There are 3 properties you can set to specify the proxy that will be used by the http protocol handler:

  • http.proxyHost: the host name of the proxy server
  • http.proxyPort: the port number, the default value being 80
  • http.nonProxyHosts: a list of hosts that should be reached directly, bypassing the proxy

Example of using command line option to set proxy configuration on java
java -Dhttp.proxyPort=8080
-Dhttp.noProxyHosts=”localhost|” YourAppMainClass

Example of using code to configure proxy setting on java
//Set the http proxy to
System.setProperty("http.proxyHost", "");
System.setPropery("http.proxyPort", "8080");
// Next connection will be through proxy.

There are other proxy settings that you can set as well such as https, ftp, socks.
More resources:

2 Responses to “Setting http Proxy for Java Application”

  1. FromParis Says:

    Thanks for your help.
    1 day searching every where a solution, and i get it !!!
    Many Thanks

  2. Edson Says:

    Thank you.

Leave a Reply