Java App Behind Proxy to Use Http_Proxy Variable in Linux

How do I set the proxy to be used by the JVM

From the Java documentation (not the javadoc API):

http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

Set the JVM flags http.proxyHost and http.proxyPort when starting your JVM on the command line.
This is usually done in a shell script (in Unix) or bat file (in Windows). Here's the example with the Unix shell script:

JAVA_FLAGS=-Dhttp.proxyHost=10.0.0.100 -Dhttp.proxyPort=8800
java ${JAVA_FLAGS} ...

When using containers such as JBoss or WebLogic, my solution is to edit the start-up scripts supplied by the vendor.

Many developers are familiar with the Java API (javadocs), but many times the rest of the documentation is overlooked. It contains a lot of interesting information: http://download.oracle.com/javase/6/docs/technotes/guides/


Update : If you do not want to use proxy to resolve some local/intranet hosts, check out the comment from @Tomalak:

Also don't forget the http.nonProxyHosts property!

-Dhttp.nonProxyHosts="localhost|127.0.0.1|10.*.*.*|*.example.com|etc"

Setting system-wide/global proxy in java

The solution was different for each platform, I currently only implemented the proxy settings on Windows and OSX.

  • Modify the preferences.plist file on OSX, this is the file located at

/Library/Preferences/SystemConfiguration/preferences.plist

  • Modify the registry on Windows, editing the following path

Software\Microsoft\Windows\CurrentVersion\Internet Settings

Set http_proxy environment variable with domain user and pass in windows


  1. It's common for hosts to not respond to ICMP echo, so ping will time out, it doesn't mean anything any more (it used to back in the day when everything responded).

  2. Proxy credentials = Domain credentials? Maybe. Depends on whether the proxy is configured to use your domain accounts or not. Since it's TMG, I'd say that is very likely.

  3. http_proxy variable for what? Browsers don't use environment variables for proxy config.

That error 407 is an auth challenge from the proxy. You won't get any further until you start providing credentials that the proxy will accept.



Related Topics



Leave a reply



Submit