- Maven has its own settings.xml. This is a global file in C:\apache-maven-2.2.1\conf. But the file content is basically all commented out. So it is basically just a placeholder there.
- Maven then uses the settings.xml in the user directory C:\Users\userid\.m2
- Inside MyCompany network, the http traffic usually uses a proxy.
- For IE browser, you can configure
the proxy by following the menu: tools --> internet options --> connections - LAN settings. Then
you can check "Use Automatic configuration script" and set the URL to the script in the "Address"
input field. For example, you can specify the following in the Address:
If the MyCompany proxy is not set, it seems that no traffic can go outside. Even the URL www.google.com will time out. And the central maven repository http://central.maven.org/maven2/ will time out too of course.
- For maven, the proxy is configured using the<proxy> tag inside the settings.xml file. For
<proxies> <proxy> <active/> <port>80</port> <host>internet.myCompany.com</host> <id>my proxy</id> <nonProxyHosts>*.myCompany.com</nonProxyHosts> </proxy> </proxies>
- Maven uses the Central Repository http://central.maven.org/maven2/ as the default repository. Even if you do not specify any repository in the settings.xml file, maven will use this Central repository.
- By default, Maven will download from the central repository. To override this, you need to specify a mirror.
- You can force Maven to use a single repository by having it mirror all repository requests. The repository must contain all of the desired artifacts, or be able to proxy the requests to other repositories. This setting is most useful when using an internal company repository with the Maven Repository Manager to proxy external requests. To achieve this, set mirrorOf to *.
- The official Maven 2 repository is at http://repo.maven.apache.org/maven2 hosted in the US.
- The ID of the main Maven Central US repository included by default is central.
<mirrors> <mirror> <id>maven.MyCompany.com</id> <name>Maven Repository Manager running on maven.MyCompany.com</name> <url>http://maven.MyCompany.com/m2</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <repositories> <repository> <id>mvnown</id> <name>Maven Repository Manager running on maven.MyCompany.com</name> <url>http://maven.MyCompany.com/m2</url> </repository> </repositories>From the above, we can see that the maven "central" repository is overridden by the MyCompany repository. The only repository used is http://maven.MyCompany.com/m2. In one project, we got the following error messages when building the application:
Downloading: http://maven.MyCompany.com/m2/org/jboss/jboss-parent/6/jboss-parent-6.pom [INFO] Unable to find resource 'org.jboss:jboss-parent:pom:6' in repository mvnown (http://maven.MyCompany.com/m2) Downloading: http://maven.MyCompany.com/m2/org/jboss/jboss-parent/6/jboss-parent-6.pom [INFO] Unable to find resource 'org.jboss:jboss-parent:pom:6' in repository central (http://repo1.maven.org/maven2)You can see that maven tried the two repositories: Firstly repository mvnown (http://maven.MyCompany.com/m2). Secondly central (http://repo1.maven.org/maven2). The first repository is specified in the<repository> setting. The second repository is the default. This error message shows that even if you do not specify the central repository in the settings.xml, maven will still try to download libraries from that repository. In our case, it is mirrored. So what maven got is actually still mvnown (http://maven.MyCompany.com/m2)! And of course, nothing new is found there! Now if I remove the mirror for the central, what will happen? Can maven find that jboss-parente-6.pom file? You will expect that the answer should be a "Yes". And that is right! It will be found and the build will be a success!