How to enable proxy setting in Maven

To enable proxy access in Maven, define the proxy server detail in {MAVEN_HOME}/conf/settings.xml

Note
There is a high chance your company is set up an HTTP proxy server to stop user connecting to the Internet directly. If you are behind a proxy, Maven will fail to download the project dependencies.

P.S Tested with Maven 3.6

1. Proxy Access

1. Open the Maven settings.xml, find proxies tag :

{MAVEN_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>

1.2 Defined the proxy server setting like below :


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

1.3 Done, the Apache Maven should be able to connect to the Internet via the proxy server.

References

  1. Configuring a proxy

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
21 Comment threads
11 Thread replies
1 Followers
 
Most reacted comment
Hottest comment thread
29 Comment authors
SouravPrashantAkashVeeramaniNasrul Recent comment authors
newest oldest most voted
Punit
Guest
Punit

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

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

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

trackback
Maven Tutorials | Tutorials

[…] Enable the proxy in Maven To use proxy server to connect internet, you have to configure the proxy setting in Maven. […]

Pawash Ahuja
Guest
Pawash Ahuja

Configured my settings.xml file to incude the proxy. However, when I tried to use mvn archetype:generate, this was the error: Please advise. TIA maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): aurl003.us.alcatel-lucent.com [WARNING] Failure to transfer org.codehaus.mojo/maven-metadata.xml from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): aurl003.us.alcatel-lucent.com [INFO] ———————————————————————— [INFO] BUILD FAILURE [INFO] ———————————————————————— [INFO] Total time: 40.518 s [INFO] Finished at: 2016-06-09T14:19:31+00:00 [INFO] Final Memory: 13M/102M [INFO] ———————————————————————— [ERROR] No plugin found for prefix ‘archetype’ in the… Read more »

Bikash
Guest
Bikash

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

Sourav
Guest
Sourav

In my case i dont have any address,means it is blank completely.i have port no but not address.i am using my own system not under any company or industry. can any one help me out?

Prashant
Guest
Prashant

Dear Mkyong, How do I set up my proxy to take the system setting as the proxy details are not know to me as our desktop support uses script which we can see. The script calls and handles the access requests.
Thanks

Akash
Guest
Akash

Very Useful , thanks , but i do have a doubt, can we enable this proxy for just one of the mirrors we are using , i actually have a Requirement , where only one of the mirrors should go through the Proxy.

AnNik
Guest
AnNik

I`d like to add nonProxy hosts aka 10.0.0.0/8 – what is solution for this case ?

KR
Guest
KR

Thank you, It just works

Iyshwarya
Guest
Iyshwarya

I’m new to maven and I have a query. Is it possible to configure multiple proxies in maven? If so how ?

Aditya C
Guest
Aditya C

Thanks a Lot …It helped me alot..

Elom Atsou Agboka
Guest
Elom Atsou Agboka

Nice job !!!

Manish
Guest
Manish

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

rajmohan
Guest
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… Read more »

LK
Guest
LK

Does someone know the solusion for this error?

Paddy
Guest
Paddy

As Apostolos mantioned, try using wagon jar to solve this problem. See this link for further details :

http://thiranjith.com/2012/10/31/how-to-configure-maven-to-work-with-ntlm-proxies/

Apostolos
Guest
Apostolos

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

Deepak Sabharwal
Guest
Deepak Sabharwal

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

jesse
Guest
jesse

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

M J Kulathinal
Guest
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
Guest
glenn

it works

Nasrul
Guest
Nasrul

Do you have any idea how to get the proxy by ourselves rather than reaching out to the network team

Unblock Proxy
Guest
Unblock Proxy

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

Rohit
Guest
Rohit

Thanks this was very useful

Klaudia Saric
Guest
Klaudia Saric

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

Prasath
Guest
Prasath

Thanks for the article. It looks good.

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

Thanks

alejogabriel
Guest
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