Repository
1. local repository
1) summary:
Store all your projects' dependencies (like plugin jars and other files). In simple, when you build a maven project, it will automatically download the dependencies here.
2) location:
by default, it is %home%/.m2. We can change it in /etc/maven2/settings.xml as the following:
<settings>
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>/home/wliu/maven_repo</localRepository>
2. Center repository
1) Summary:
the default place to download the project's dependency.
When build a project, first it will check the dependencies element in the POM.xml to identify the dependencies. Then try to get the dependencies from the local repository, if fails, download them from the center repository. If still cannot find, need to add other repository to the element: repositories to download the dependency files.
In simple:
- Search in Maven local repository, if not found, go step 2, else exit.
- Search in Maven central repository, if not found, go step 3, else exit.
- Search in custom remote repository, if not found, prompt error message, else exit.
2) location:
We can find it in POM.xml file:
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
3. dependency
1) summary
Define all the dependencies of the project
2) location
In POM.xml, there is an element:denpendencies
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
4. install custom libraries to local repository
2 steps.
step 1:
mvn install:install-file -Dfile=/home/wliu/dom4j-1.6.1.jar -DgroupId=dom4j -DartifactId=dom4j -Dversion=1.6.1 -Dpackaging=jar
step 2:
after installed, declare dom4j in the pom.xml as the dependency.
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
Reference:
1. http://www.mkyong.com/tutorials/maven-tutorials/