Main Tutorials

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 Author

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

Subscribe
Notify of
32 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Siba
4 years ago

I have added above given proxy in my setting.xml file then I did mvn clean after that i am getting below exception
from/to central (https://repo.maven.apache.org/maven2): proxy.mkyong.com: Unknown host proxy.mkyong.com
Can please help me why I am getting this exception and how I have to change here.

Thanks,

Punit
11 years ago

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

Sourav
4 years ago

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
4 years ago

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
5 years ago

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

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

KR
8 years ago

Thank you, It just works

Iyshwarya
8 years ago

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

Aditya C
9 years ago

Thanks a Lot …It helped me alot..

Elom Atsou Agboka
10 years ago

Nice job !!!

Manish
10 years ago

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

rajmohan
11 years ago

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

Apostolos
10 years ago
Reply to  rajmohan

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

LK
11 years ago
Reply to  rajmohan

Does someone know the solusion for this error?

Paddy
10 years ago
Reply to  LK

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/

Deepak Sabharwal
12 years ago

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

jesse
12 years ago

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

M J Kulathinal
12 years ago
Reply to  jesse

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

Nasrul
5 years ago
Reply to  M J Kulathinal

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

glenn
10 years ago
Reply to  M J Kulathinal

it works

Unblock Proxy
13 years ago

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

Rohit
13 years ago

Thanks this was very useful

Klaudia Saric
14 years ago

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

Prasath
14 years ago

Thanks for the article. It looks good.

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

Thanks

Veeramani
5 years ago
Reply to  mkyong

Hi, can you please suggest how to configure host and port tag in maven settings.xml when connecting from home network. when connecting fm home, no proxy and no port due to auto proxy detect mode. if will give blank in host and port tag, will throw a error while parsing host and port.

Pawash Ahuja
7 years ago

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 current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/root/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [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/NoPluginFoundForPrefixException

Bikash
12 years ago

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

alejogabriel
10 years ago

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