How to enable proxy settings in Maven?

Learn how you can enable the proxy settings in Maven's settings.xml file?

How to enable proxy settings in Maven?

Maven 3 Tutorial: How to enable proxy settings in Maven?

In this tutorial I will teach you how to enable proxy settings in maven? If your computer is behind firewall and you are accessing Internet through proxy server then the Maven build tools is not able to access the remote repository. To enable the proxy settings you have to make changes in the settings.xml file of Maven.

After making the changes in the settings.xml the Maven build tool will be able to make contact to the proxy server and then access the remote repository. This way you will be able to use the Maven build tool if you are behind firewall.

In Maven there is a file called settings.xml in the conf directory of your Maven installation. E.g. {MAVEN_HOME}/conf/settings.xml. So, first of go to the directory where Maven is installed and then go to the conf directory and you should be able to find the settings.xml file there.

Here are the steps to enable the proxy settings in Maven

Step 1: Open the file settings.xml and find the code given below:

<!-- 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>

You will to uncomment the proxy tag and add the host name, user name and password of your proxy server.

Step 2: Uncomment the <proxy> tag and make the necessary changes in the host, username, password and port settings. Here is the example of the settings:

<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></username>
<password></password>
<host>192.168.10.80</host>
<port>9090</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>

</proxies>

You should enter connect IP address, Username, Password and port number of your proxy sever. After making the above changes you should be able to use Maven through proxy server.

Here in this tutorial you have learned how to make changes in the settings.xml file of Maven to enable the remote repository access.

Read more Maven 3 tutorials.