Let’s Play! - My Play Framework Learning Journey (2) - SBT HTTP Proxy Configuration

In order to run the example project, you will need to get sbt installed and configured. The key challenge I had with sbt is to configure it for HTTP proxy, which is common in corporate environment.

To make sbt working correctly behind an HTTP proxy, you can set the following system properties:

  • http.proxyHost
  • http.proxyPort
  • http.proxyUserName
  • http.proxyPassword
  • https.proxyHost
  • https.proxyPort
  • https.proxyUserName
  • https.proxyPassword
  • http.nonProxyHosts
  • https.nonProxyHosts (this may not be needed, but worth a try if http.nonProxyHosts is not working)

It will be easier to install a NTLM proxy like CNTLM so that you don’t need to specify the user name and password here.

Take note that if there are multiple hosts to be defined in nonProxyHosts, they are to be separated using “|”, as required by Java.

Furthermore, I found that in Windows, “|” must be escaped using “^”. See example below:

-Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -Dhttp.nonProxyHosts="localhost^|nexus"

Without the escape character (^), you will get an error “| was unexpected at this time”. This might be fixed in the future. See this sbt issue in Github.

The above can be set at the sbt command line:

sbt -Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -Dhttp.nonProxyHosts="localhost^|nexus" compile

Or in JAVA_OPTS environment variable:

set JAVA_OPTS=-Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -Dhttp.nonProxyHosts="localhost^|nexus"

sbt on Windows installs a sbt.bat file. This file will look for JAVA_OPTS environment variable and use its value.

Additional References

Go Top
comments powered by Disqus