Java applications connect to the Internet very often. If you want to use the proxy server to connect to the Internet, you need to set your JVM to use the proxy. To do this, you can set:
http.proxyHost and http.proxyPort. These are JVM flags. We will explain how to set them correctly.
JVM flags
You can set them when starting your JVM on the command line. In Windows, you can use a bat file. In Unix a shell script:
1 2 3 4 |
PROXY_FLAGS=-Dhttp.proxyHost=1.2.3.4 -Dhttp.proxyPort=8080 java ${PROXY_FLAGS} ... |
The situation is slightly different when you are using containers (such as WebLogic). Then you need to edit the startup scripts which your container provides.
nonProxyHost property
When you don’t want to use the proxy to resolve some local hosts you can use http.nonProxyHosts property. The usage:
1 2 3 |
-Dhttp.nonProxyHosts="localhost|127.0.0.1|1.2.*.*|*.test.com" |