Maven學習八之pom.xml簡介以及客戶端下載包的流程
一 POM.xml簡介
看一個簡單的小例子
<project xmlns="https://maven.apache.org/POM/4.0.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<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>https://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文件基本節點介紹:
<project>文件的根節點。
<modelversion>pom.xml使用的對象模型版本。
<groupId>創建項目的組織或團體的唯一Id。
<artifactId>項目的唯一Id,可視為項目名。
<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>https://maven.apache.org</url>
<repositories>
<repository>
<id>xy-central</id>
<name>xycentral</name>
<url>https://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>https://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倉庫並引用。
參考地址:https://wenku.baidu.com/view/edd1f2b765ce0508763213ad.html
最後更新:2017-04-03 16:49:31