Maven學習二: Maven POM

      本是打算通過學用Maven來把Rest Demo的Jersey框架相關jar包管理並使用起來,結果發現Maven這個工具我並不熟悉的,於是算作一個小插曲,先把略微系統性的學習一下Maven的配置以及使用等等。

     前兩篇文章,把Maven的環境配置說了一下,這並不是Maven的入門,而是剛剛具備了入門的基礎。

     Maven POM,就是Maven 管理下的Project Object Model,代表項目對象模型。它是工作在Maven的基本單位。這是一個XML文件。它包含的項目使用Maven來構建該項目和各種配置的詳細信息。

     POM也包含了目標和插件。在執行任務或目標時,Maven會找到在當前目錄中的POM文件並進行讀取,得到所需要的配置信息,然後執行的目標。部分的配置,可以在POM如下:

  • project dependencies

  • plugins

  • goals

  • build profiles

  • project version

  • developers

  • mailing list

    創建一個POM之前,我們應該先決定項目組(groupId),它的名字(artifactId)和它的版本,因爲這些屬性是用來作唯一標示的。

    例子POM

<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.companyname.project-group</groupId> <artifactId>project</artifactId> <version>1.0</version> </project>
應當指出,應該有一個單一的POM文件爲每個項目。
  • 所有的POM文件要求的項目元素和三個必填字段: groupId,artifactId版本。

  • 在庫中的項目符號是:groupId:artifactId:version.

  • 根元素的pom.xml是項目,它有三個主要的子節點:

NodeDescription
groupIdThis is an Id of project's group. This is generally unique amongst an organization or a project. For example, a banking group com.company.bank has all bank related projects.
artifactIdThis is an Id of the project.This is generally name of the project. For example, consumer-banking. Along with the groupId, the artifactId defines the artifact's location within the repository.
versionThis is the version of the project.Along with the groupId, It is used within an artifact's repository to separate versions from each other. For example: 

com.company.bank:consumer-banking:1.0

com.company.bank:consumer-banking:1.1.



發佈了323 篇原創文章 · 獲贊 25 · 訪問量 159萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章