二:Maven中pom.xml元素詳解,mavenpom.xml

來源:互聯網
上載者:User

二:Maven中pom.xml元素詳解,mavenpom.xml

轉載請註明原文地址:http://www.cnblogs.com/ygj0930/p/6628201.html 

    一個pom.xml中包含了許多標籤,各個標籤是對專案生命週期、依賴管理的配置。常用的主要有:

    1:<peoject>:pom.xml的根標籤,一個maven項目用一對<peoject></project>標籤包裹。

    2:<modelVersion>:maven的版本

    3:當前項目的座標以及打包方式:

        <groupId>:企業網址反寫+項目名

        <artifactId>:項目名-模組名

        <version>:版本號碼+類型

                        版本號碼由三個整數表示,每個整數用“.”分隔,表示:大版本號碼.分支版本號碼.小版本號碼

                        類型:版本類型。主要有:snapshot快照版本(簡化版本)、alpha內測版、beta公測版、release穩定版、GA正式發布版

        <packaging>:打包類型,預設是jar,可以配置成war、zip、pom類型。

    4:<name>:當前項目名

    5:<url>:項目地址

    6:<description>:項目描述資訊

    7:<developers>:開發人員資訊

    8:<licenses>:項目許可證資訊,用來發布時授予別人使用此項目的權利

    9:<organization>:組織資訊,公司資訊

    以上都是對這個maven項目的相關資訊配置。

    10:<properties>:屬性值標籤,也叫變數標籤。與Ant中的property一樣,可以通過這個標籤包含一些屬性並指定屬性值。那麼在pom.xml的其他地方,可以通過EL運算式訪問變數的方法——${屬性名稱}  來擷取具體的屬性值。一般這個用來作為整個pom.xml中需要重複使用的內容或者全域變數使用。

    11:依賴標籤

<dependencies>    <!--一個依賴包-->    <dependency>       <!--通過座標指定依賴包-->        <groupId>        </groupId>        <artifactId>      </artifactId>        <version>        </version>        <!--可選項:依賴範圍。有六個可選值:常用compile/provided/test/runtime等-->        <scope>一個範圍</scope>        <!--可選項:排除依賴傳遞:即:當前項目依賴當前配置的依賴包A時,如果這個依賴包又依賴其他包B,這裡可以選擇排除依賴的傳遞性,不下載匯入B-->         <exclusions>            <exclusion>
              <!--被排除的依賴包座標-->              <groupId> </groupId>              <artifactId> </artifactId>              <version> </version>
            </exclusion>         </exclusions>    </dependency></dependencies>

 

    12:依賴管理標籤:主要用於制定父pom.xml,其他項目可以繼承這個pom.xml,從而避免重複定義某些depency。

<depencyManagement>    <depencies>       <depency>           依賴包的座標...       </depency>    </depencies></depencyManagement>

    13:<build>:項目支援標籤,一般用來引入外掛程式

<build>    <plugins>      <plugin>         <!--外掛程式座標-->         <groupId>         </groupId>         <artifactId>         </artifactId>         <version>         </version>         其他設定...      </plugin>    </plugins></build>

    14:<parent>:繼承標籤,用於繼承父項目。

    15:<moudules>:彙總標籤,用於彙總多個maven項目,這樣用某指令執行這個pom就會把彙總的各項目全部執行,同時處理多重專案。

 

    樣本:一個簡單的構建JavaWeb項目的pom.xml如下:

<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/maven-v4_0_0.xsd">    <modelVersion>4.0.0</modelVersion>  <groupId>com.test</groupId>  <artifactId>WebApp</artifactId>  <packaging>war</packaging>  <version>1.0</version>    <name>WebApp Maven Webapp</name>  <url>http://maven.apache.org</url>    <dependencies>        <dependency>      <groupId>commons-fileupload</groupId>      <artifactId>commons-fileupload</artifactId>      <version>1.2.1</version>    </dependency>        <!--commons-io為commons-fileupload的可選依賴包-->    <dependency>      <groupId>commons-io</groupId>      <artifactId>commons-io</artifactId>      <version>1.3.2</version>    </dependency>  </dependencies>    <build>    <finalName>WebApp</finalName>  </build></project>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.