Maven2的對象模型POM

pom作爲項目對象模型,通過xml表示maven項目,使用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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!-- 基本設置 -->
    <groupId>...</groupId> <!-- 項目或者組織的唯一標誌,並且配置時生成的路徑也是由此生成,如org.codehaus.mojo生成的相對路徑爲/org/codehaus/mojo -->
    <artifactId>...</artifactId>  <!--項目的通用名稱-->
    <version>...</version>  <!--項目的版本-->
    <packaging>...</packaging>  <!--打包的機制-->
    <dependencies>...</dependencies>
    <parent>...</parent>
    <dependencyManagement>...</dependencyManagement>
    <modules>...</modules>
    <properties>...</properties>
    <!-- 構建過程的設置 -->
    <build>...</build>
    <reporting>...</reporting>
    <!-- 項目信息設置 -->
    <name>...</name>
    <description>...</description>
    <url>...</url>
    <inceptionYear>...</inceptionYear>
    <licenses>...</licenses>
    <organization>...</organization>
    <developers>...</developers>
    <contributors>...</contributors>
    <!-- 環境設置 -->
    <issueManagement>...</issueManagement>
    <ciManagement>...</ciManagement>
    <mailingLists>...</mailingLists>
    <scm>...</scm>
    <prerequisites>...</prerequisites>
    <repositories>...</repositories>
    <pluginRepositories>...</pluginRepositories>
    <distributionManagement>...</distributionManagement>
    <profiles>...</profiles>
</project>

pom定義了最小的maven2元素,允許groupId,artifactId,version的所有需要的元素。

pom關係:依賴,集成,合成

依賴關係:

<dependencies>  
    <dependency>  
        <groupId>junit</groupId>  
        <artifactId>junit</artifactId>  
        <version>4.0</version>  
        <type>jar</type>  
        <scope>test</scope>  
        <optional>true</optional>  
    </dependency>  
    ...  
</dependencies>

繼承關係

<project> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>my-parent</artifactId> 
    <version>2.0</version> 
    <packaging>pom</packaging> 
</project>

合成(或者多個模塊)

一個項目有多個模塊,也叫做多重模塊,或者合成項目。

<project> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>my-parent</artifactId> 
    <version>2.0</version> 
    <modules> 
        <module>my-project1<module> 
        <module>my-project2<module> 
    </modules> 
</project> 

插件

在build時,執行的插件,比較有用的部分,如使用jdk6.0編譯等等

<project> 
    <build> 
    ... 
    <plugins> 
        <plugin> 
            <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-jar-plugin</artifactId> 
            <version>2.0</version> 
            <!-- true或false,是否加載插件擴展,默認false-->
            <extensions>false</extensions> 
            <!-- true或false,是否此插件配置會應用與pom-->
            <inherited>true</inherited> 
            <!-- 指定插件配置-->
            <configuration> 
                <classifier>test</classifier> 
            </configuration> 
            <!-- 插件需要依賴的包-->
            <dependencies>...</dependencies> 
            <!-- 用於配置execution目標,一個插件可以有多個目標-->
            <executions>...</executions> 
        </plugin> 
    </plugins> 
    </build> 
</project> 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章