Reference Original: http://www.wirelessqa.com/?p=289
1. What is MAVEN Warehouse
In the case of MAVEN, for example, when we used ant to build a project, under the project directory, we would often see a subdirectory called/lib, where all kinds of third-party dependent jar files, such as Log4j.jar,junit.jar and so on, are stored.
For each project you build, you need to create such a/lib directory, and then copy a pair of jar files, which is obviously duplicated. Repetition is always the starting point for nightmares, and multiple projects that do not share the same jar files will not only result in wasted disk resources, but also make consistency management of versions difficult.
Also, if you use version management tools such as SVN (you are not using the version management tool.) Try SVN now, it can help you solve a lot of headaches, you need to submit a large number of jar files to the code base, but the version management tool in the processing of binary files is not good.
The Maven repository is where all the jar files (war,zip,pom, etc.) are placed, and all MAVEN projects can get the dependency jar they need from the same MAVEN repository, which saves disk resources. In addition, because all jars in the Maven repository have their own coordinates, the coordinates tell maven its group ID, artifact ID, version, packaging method, and so on, so MAVEN projects can be easily dependent on version management. Neither do you. To submit the jar file to the SCM repository, you can create an organization-level MAVEN repository for all members to use.
In short, maven repositories can help us manage artifacts (primarily jars).
2. Local warehouse vs. remote Repository
2.1 Local warehouses
When you run MAVEN, any artifacts required by MAVEN are obtained directly from the local repository. If the local repository does not, it will first attempt to download artifacts from the remote repository to the local repository and then use the artifacts from the local warehouse.
For example, your project is configured with junit-3.8 dependencies, and when you run MVN test, MAVEN needs to use the junit-3.8 jar file, which first locates the local repository based on coordinates and uses it directly if found. If not, MAVEN checks the available remote warehouse configurations and then tries each of these remote warehouses to download the junit-3.8 jar file, and if the remote repository exists, MAVEN downloads it to the local repository and then uses it. If Maven has not been able to download the file after trying all the remote repositories, it will error.
The MAVEN default local warehouse address is ${user.home}/.m2/repository. In other words, a user will have a local repository.
You can also customize the location of the local warehouse and modify the ${user.home}/.m2/settings.xml:
3 |
<localRepository>D:/java/repository</localRepository> |
You can also specify the local warehouse location at run time: