Maven學習八之pom.xml簡介

一 POM.xml簡介html

 

看一個簡單的小例子apache

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/mave    
n-v4_0_0.xsd">
    
maven

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xy.company</groupId>
    <artifactId>MavenResource</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>MavenResource</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
單元測試

</project>測試

 

pom.xml文件基本節點介紹:ui


<project>文件的根節點。url

 

<modelversion>pom.xml使用的對象模型版本。spa


<groupId>建立項目的組織或團體的惟一Id。插件


<artifactId>項目的惟一Id,可視爲項目名。xml


<packaging>打包物的擴展名,通常有JAR,WAR,EAR等。


<version>產品的版本號。


<name>項目的顯示名,經常使用於Maven生成的文檔。


<url>組織的站點,經常使用於Maven生成的文檔,能夠放你公司的主頁地址。


<description>項目的描述,經常使用於Maven生成的文檔。


<repositories>資源地址,全部的依賴包將從次地址下載,其中若是snapshot爲資源快照,相對不穩定,而release爲穩定版本。


<pluginRepositories> 插件地址,由於maven的全部功能都是使用插件來實現功能的,所以須要從特定的地址下載插件包。
 

<build>功能集標籤,在此標籤下面能夠定義一系列的插件以實現功能,經常使用插件有如下兩種:
• maven-surefire-plugin單元測試的插件,在此插件下面能夠設置一些列的參數
• maven-compiler-plugin代碼編譯插件,在用此插件的時候必定要設置source的版本,默認的是JDK1.3

 


<dependencies>項目須要的全部依賴的包。

 

其中repositories和pluginRepositories就是放私服的地址,即咱們前幾講的nexus的public倉庫組地址。

 

<project >

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xy.company</groupId>
    <artifactId>MavenResource</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>MavenResource</name>
    <url>http://maven.apache.org</url>

   <repositories>
   <repository>
    <id>xy-central</id>
    <name>xycentral</name>
    <url>http://localhost:8080/nexus-2.2-01/content/groups/public/</url>
    <releases>
     <enabled>true</enabled>
    </releases>
    <snapshots>
     <enabled>false</enabled>
    </snapshots>
   </repository>
 </repositories>


  <pluginRepositories>
  <pluginRepository>
   <id>xy-central</id>
   <name>xycentral</name>
   <url>http://localhost:8080/nexus-2.2-01/content/groups/public/</url>
   <layout>default</layout>
   <snapshots>
    <enabled>false</enabled>
   </snapshots>
   <releases>
    <updatePolicy>never</updatePolicy>
   </releases>
  </pluginRepository>
 </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

 

二客戶端下載包流程

 

好比客戶端須要一個junit的jar包

第一步:到本地倉庫找該jar包,找到結束。沒找到下一步。

第二步:到pom配置的私服倉庫去找,即pom.xml配置的repositories標籤。如找到下載到本地倉庫並引用。沒找到下一步。

第三步:到maven的中央倉庫去找,如找到同時下載到本地倉庫和私服的central倉庫並引用。

 

 

參考地址:http://wenku.baidu.com/view/edd1f2b765ce0508763213ad.html

相關文章
相關標籤/搜索