Sometimes inside corporate networks you may not have direct access to the Internet, but only through a proxy. In this article, we will look at how to use maven through a proxy.
1. Register proxy in settings
You need to ensure the proxies section in either the global settings (maven dir/conf/settings.xml), or user settings (${user.home}/.m2/settings.xml) is configured correctly. It is better to do this in your user settings to avoid storing the password in plain text in a public location.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[...] <proxies> <proxy> <active>true</active> <protocol>http</protocol> <host>proxy.somewhere.com</host> <port>8080</port> <username>proxyuser</username> <password>somepassword</password> <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts> </proxy> </proxies> [...] |
2. Set MAVEN_OPTS environment variable
Linux (bash):
1 |
export MAVEN_OPTS="-Dhttp.proxyHost=<host> -Dhttp.proxyPort=<port> -Dhttps.proxyHost=<host> -Dhttps.proxyPort=<port>" |
Windows:
1 |
set MAVEN_OPTS="-Dhttp.proxyHost=<host> -Dhttp.proxyPort=<port> -Dhttps.proxyHost=<host> -Dhttps.proxyPort=<port>" |