How to Set JVM Proxy Setting Without Touching the Code

First of all, proxy server is a server that acts as an intermediary for requests from clients seeking resources from other server (or Internet). Usually companies' Internet connection facility use proxy to make it possible to control their employees' browsing activities, such as:

  • Define someone's bandwidth limit for a specific period
  • Define a blacklist of websites, within a specific time schedule or not
  • Storing employees' browsing history log
  • Storing employees' chatting history log
Commonly proxy servers are used for security reason, and those points above have to be implemented with a certain networking skills or by using some helper tools.

By adding these 3 JVM arguments to java, your application will use the proxy network to create HTTP requests:
  • http.useProxy=true
  • http.proxyHost=[domain or IP]
  • http.proxyPort=[port number]
  • http.nonProxyHosts=[regex of proxy exclusions]
java -Dhttp.useProxy=true -Dhttp.proxyHost= -Dhttp.proxyPort=8877 -Dhttp.nonProxyHosts=|localhost -jar testsomething.jar

For HTTPS, the arguments are:
  • https.proxyHost
  • https.proxyPort
  • http.nonProxyHosts
For FTP, the arguments are:
  • ftp.proxyHost
  • ftp.proxyPort
  • ftp.nonProxyHosts
If the proxy network is a HTTP Proxy that requires authentication with username and password, then you have to use and it means that you have to touch your code.

If the proxy network is a SOCKS v5 Proxy, then again it can be done by using JVM arguments:
  • socksProxyHost=[domain or IP]
  • socksProxyPort=[port number]
  •[the username]
  •[the password]
java -DsocksProxyHost= -DsocksProxyPort=8877

For further information:
Networking Properties reference from
Java Networking and Proxies from

5 comments: (+add yours?)

Anonymous said...

Thx, concise summary with useful examples!

administrator said...

excellent tips

Anonymous said...

How does one specify username and password for the http proxy server without touching the code ?

Martin Rybak said...

Thank you so much. Saved the day.

Anonymous said...

Thank you.
Saved my day too.