How to enable proxy setting in Maven
There is a high chance your company is set up a firewall and an HTTP proxy server to stop user connects to internet directly. If you are behind a proxy, Maven will fail to download any dependencies.
To make it work, you have to declare the proxy server setting in Maven configuration file settings.xml.
1. Maven configuration file
Find {M2_HOME}/conf/settings.xml, and put your proxies detail inside.
{M2_HOME}/conf/settings.xml
<!-- proxies | This is a list of proxies which can be used on this machine to connect to the network. | Unless otherwise specified (by system property or command-line switch), the first proxy | specification in this list marked as active will be used. |--> <proxies> <!-- proxy | Specification for one proxy, to be used in connecting to the network. | <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <username>proxyuser</</username> <password>proxypass</password> <host>proxy.host.net</host> <port>80</port> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> --> </proxies>
Un-comment the proxy options and fill in your proxy server detail.
<!-- proxies | This is a list of proxies which can be used on this machine to connect to the network. | Unless otherwise specified (by system property or command-line switch), the first proxy | specification in this list marked as active will be used. |--> <proxies> <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <username>mkyong</username> <password>password</password> <host>proxy.mkyong.com</host> <port>8888</port> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> </proxies>
2. Saved it.
Done, your Apache Maven should be able to connect to the Internet via your proxy server now.
Note
Restart is NOT required, how do you restart Maven? Maven is just a command, when you call it, it will read this file again.
Restart is NOT required, how do you restart Maven? Maven is just a command, when you call it, it will read this file again.

Hi Thanks for the post, you always have great tutorials.
just wanted to know, what are the other elements, i mean:
do i need to change only host, i mean i need to create proxy for “http://repo.jenkins-ci.org/public/org/jenkins-ci”.
so i need to change the host only, rest i need to leave as it is??
Yes, not working?
C:\Git\cas>
C:\Git\cas>mvn clean package -P local -Dmaven.test.skip=true
[INFO] Scanning for projects…
[INFO]
[INFO] ————————————————————————
[INFO] Building cas 1.2.2
[INFO] ————————————————————————
Downloading: http://download.java.net/maven/2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
Downloading: http://repository.codehaus.org/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 0.827s
[INFO] Finished at: Wed Jun 27 16:33:19 IST 2012
[INFO] Final Memory: 2M/5M
[INFO] ————————————————————————
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven
.plugins:maven-clean-plugin:jar:2.4.1: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.4.1 from/to maven2-repository.dev.java.net (http://do
wnload.java.net/maven/2): Not authorized by proxy, ReasonPhrase:Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to th
e Web Proxy filter is denied. ). -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
Does someone know the solusion for this error?
Defined your proxy setting? The error message stated “Not authorized by proxy, ReasonPhrase:Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to th
e Web Proxy filter is denied).”
Contact your system adminsitrator for further action.
Hi, its good to use maven for project management. nice work !!!
Thanks for tutorial but, I want to know is it ok to
give IP address in instead of name.
yes, you can put IP address, instead of name.
i am using automatic configuration script to connect to internet. how do i set in this scenario
I had the same issue – was trying to build with maven but had to go through an automatic configuration script for a proxy server. I managed to sort the issue by using the setting in the maven settings.xml file and defining the proxy server details which were defined in the configuration script which I managed to get from the network team and it worked … so instead of using the script path, use the actual proxy definitions in the settings file for maven and it will work
it works
Looking through that information. It’s very usefull for us…
Thanks this was very useful
Thanks for this post, answers a bunch of questions I was having.
Thanks for the article. It looks good.
Please kindly write an article how to make use of maven in the projects.
Thanks
Hi,
Ya , writing a series of stuff regarding the Maven in Java development, let’s share it out :)