Tuesday, February 14, 2017

Proxy setting for Play activator and sbt

When running behind the proxy the activator should be provided with the appropriate proxy settings. Since the activator is using the sbt as a build tool, actually it is the sbt, which should be configured.

The sbt respects any HTTP, HTTPS, or FTP proxy settings from the standard environment variables.

There is a set of environment variables for proxy setting for each HTTP, HTTPS, or FTP. For example, the following are variables for HTTP:
  • http_proxy - contains a proxy server host name and colon-separated proxy port number
  • http.proxyHost - contains a proxy server host name
  • http.proxyPort - contains a proxy port number
  • http.proxyUser - contains a proxy user name
  • http.proxyPassword - contains a proxy password
Replace http with https or ftp for each HTTPS or FTP.

The http_proxy (and its HTTPS and FTP synonyms) are used for setting as environment variables.
The values http.xxxx - as a JVM arguments.

The way to provide the proxy settings depends on OS and required scope.

Proxy setting on Linux


Proxy setting may be done in several ways.

Setting with the JVM arguments

The proxy setting may be provided as JVM arguments of activator or sbt command. For example:
 activator -Dhttp.proxyHost=proxyServerName.com -Dhttp.proxyPort=8080 run
Note: proxy server host name in http.proxyHost should be without http:\\ part. The proper format is:
 proxyServerName.com
and not
 http://proxyServerName.com
The JVM arguments should be provided on each activator call.

Setting via the environment variables

More convenient way is to set the environment variables with the export command. For example:
 export http_proxy=http://proxyServerName.com:8080
 export https_proxy=http://proxyServerName.com:8080
The export calls may be put into a small script, which should be executed on the terminal once before running of activator or sbt command.

The script may be even run from .bashrc file (or its analog). In this case each terminal will inherit this proxy setting.

Proxy setting on Windows


Proxy setting may be done in several ways.

Setting with the JVM arguments

The proxy setting as JVM arguments should be done in the similar way as it is done for Linux. The JVM arguments should be provided on each activator call.

Setting via the environment variables

Setting of the environment variables is a bit different on Windows and is done with set command. For example:
 set http_proxy=http://proxyServerName.com:8080
 set https_proxy=http://proxyServerName.com:8080

The set calls may be put in a batch file, which should be executed on the console once before running of activator or sbt command. It may be also put right into the activator.bat file.

Setting via the sbt configuration

The proxy setting may be done with sbt configuration file. The sbt configuration should be defined for each activator and "pure" sbt:
1. Edit the file [sbt_root]\conf\sbtconfig.txt and add the proxy setting as JVM arguments. For example:
 -Dhttps.proxyHost=proxyServerName.com
 -Dhttps.proxyPort=8080
 -Dhttp.proxyHost=proxyServerName.com
 -Dhttp.proxyPort=8080
2. Edit the files [activatortor-root]/conf/sbtconfig.txt and add the proxy setting as JVM arguments, similar to sbt setting above.

Useful links:

1 comment :

jonas brothers said...

I dont have any kind of "host" here this is automatic script

About the author

My Photo
I trust only simple code and believe that code should be handsome. This is not a matter of technology, but professional approach, consolidated after years of software development. I enjoy to cause things working and feel very happy, when I manage to solve a problem.
Back to Top