maven: repository

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:

  1. Search in Maven local repository, if not found, go step 2, else exit.
  2. Search in Maven central repository, if not found, go step 3, else exit.
  3. 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/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值