How to enable proxy setting in Maven
There are high chance your company is set up a firewall and force the developers to connect internet via using HTTP proxy. If you are using HTTP proxy, Maven may not able to download the dependency libraries outside. To bypass it, you have to enable the proxy setting in Maven configuration file “settings.xml“.
1. Maven configuration file
Find your Maven configuration file – e.g, {M2_HOME}/conf/settings.xml
2. Edit it “settings.xml”
Find the following pattern
<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>
Comment out the proxy setting and fill in your proxy information.
<proxies> <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <username>proxyuser</username> <password>proxypass</password> <host>proxy.yourcompany.com</host> <port>80</port> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> </proxies>
4. Saved it, Done.
Apache Maven is able to connect to Internet via proxy server now.
P.S No restart is required, how do you restart Maven
? Maven is just a command , when you call it, it will read this file again.
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
Looking through that information. It’s very usefull for us…
Thanks this was very useful
[...] Enable the proxy in Maven To use proxy server to connect internet, you have to configure the proxy setting in Maven. [...]
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