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.

References

  1. Configuring a proxy
Tags :
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider making a donation to the charity, thanks.

Related Posts

Popular Posts