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.

References

  1. Configuring a proxy
Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.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 make a donation to these charities.

Comments

  • Pingback: water ionizer()

  • Pingback: alkaline water()

  • Pingback: http://webkingz.camkingz.com/()

  • Pingback: here()

  • Pingback: alkaline water()

  • Pingback: pennsylvania energy choices()

  • Pingback: pay plan()

  • Pingback: pay per day loan plans()

  • Pingback: bottled alkaline water()

  • Pingback: plan()

  • Pingback: ionizer payment plan()

  • Pingback: go here()

  • Pingback: greenlee electricians tools()

  • Pingback: house blue()

  • Pingback: zak?ad szklarski piotrków trybunalski()

  • Pingback: plumbing basics diagram()

  • Pingback: locksmith services mill creek wa()

  • Pingback: locksmith oceanside()

  • Pingback: journeyman electrician tool sets()

  • Pingback: electricians ann arbor()

  • Pingback: water ionizer pay plan loans()

  • Pingback: paypal loans()

  • Pingback: water ionizer()

  • Pingback: laan penge nu sms()

  • Pingback: stop parking()

  • Pingback: mp4 mobile porn()

  • Pingback: car parking()

  • Pingback: tv packages()

  • Pingback: stream movies()

  • Pingback: weight loss techniques()

  • Pingback: Blue Coaster33()

  • alejogabriel

    Hi, I’m new to the computer world. I recently installed a linksys router. I connect with wireless to my computer. my question is where I get the information I write on the tag “host”. Use Windows. Currently it is giving me the following error.

    Could not resolve archetype org.appfuse.archetypes:appfuse-modular-struts:RELEASE from any of the configured repositories.
    Could not resolve artifact org.appfuse.archetypes:appfuse-modular-struts:jar:RELEASE
    Missing org.appfuse.archetypes:appfuse-modular-struts:jar:RELEASE

    thanks
    Alejo

    PD: Sorry for my English

  • Elom Atsou Agboka

    Nice job !!!

  • Manish

    I don’t see here any format of setting.xml, how this file should be and what content this file may have.

  • Punit

    Hi Thanks for the post, you always have great tutorials.
    just wanted to know, what are the other elements, i mean:

    &lt;id&gt;optional&lt;/id&gt;
          &lt;active&gt;true&lt;/active&gt;
          &lt;protocol&gt;http&lt;/protocol&gt;
          &lt;username&gt;proxyuser&lt;/username&gt;
          &lt;password&gt;proxypass&lt;/password&gt;
          &lt;host&gt;proxy.yourcompany.com&lt;/host&gt;
          &lt;port&gt;80&lt;/port&gt;
          &lt;nonProxyHosts&gt;local.net|some.host.com&lt;/nonProxyHosts&gt;

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

    • http://www.mkyong.com mkyong

      Yes, not working?

  • rajmohan

    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

    • LK

      Does someone know the solusion for this error?

    • http://www.mkyong.com mkyong

      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.

    • Apostolos

      Try adding the wagon-http-lightweight-2.2.jar on the lib/ext of your maven setup.

  • Deepak Sabharwal

    Hi, its good to use maven for project management. nice work !!!

  • Bikash

    Thanks for tutorial but, I want to know is it ok to
    give IP address in instead of name.

    • http://www.mkyong.com mkyong

      yes, you can put IP address, instead of name.

  • http://no jesse

    i am using automatic configuration script to connect to internet. how do i set in this scenario

    • http://www.kulathinal.com M J Kulathinal

      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

      • glenn

        it works

  • http://unblocksitesproxy.com Unblock Proxy

    Looking through that information. It’s very usefull for us…

  • Rohit

    Thanks this was very useful

  • Pingback: Maven Tutorials | Tutorials()

  • http://www.postparrot.com Klaudia Saric

    Thanks for this post, answers a bunch of questions I was having.

  • Prasath

    Thanks for the article. It looks good.

    Please kindly write an article how to make use of maven in the projects.

    Thanks

    • mkyong

      Hi,

      Ya , writing a series of stuff regarding the Maven in Java development, let’s share it out :)