qqjianyue代碼工

          砌java代碼
          posts - 62, comments - 9, trackbacks - 0, articles - 10
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          maven pom.xml詳解

          Posted on 2008-09-16 16:21 Qzi 閱讀(125450) 評(píng)論(4)  編輯  收藏 所屬分類(lèi): appfuse2 and maven2
          <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><!--maven2.0必須是這樣寫(xiě),現(xiàn)在是maven2唯一支持的版本-->
          <!-- The Basics -->
          <groupId>...</groupId> <!--指定組名,例如:org.apache.maven-->
          <artifactId>...</artifactId> <!--指定工程名例如:appfuse-->
          <version>...</version> <!--指定版本號(hào)
          <packaging>...</packaging> <!--The current core packaging values are: pom, jar, maven-plugin, ejb, war, ear, rar, par-->
          <classifier>...</classifier> <!--projects are displayed as groupId:artifactId:packaging:classifier:version-->
          <name>...</name> <!--一些無(wú)關(guān)太重要的東西,用戶(hù)描述你的項(xiàng)目的名字,可選的-->
          <url>...</url> <!--暫時(shí)不知何物,貌似無(wú)關(guān)重要,只是寫(xiě)明開(kāi)發(fā)團(tuán)隊(duì)的網(wǎng)站,可選的-->
          <!--
          
          這里有些東西暫時(shí)不談-->
          <dependencies>...</dependencies> <!--例子:    <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.0</version>
                <type>jar</type>
                <scope>test</scope>
                <optional>true</optional>
              </dependency>
          groupId,artifactId和version這個(gè)三組合標(biāo)示依賴(lài)的具體工程,而且這個(gè)依賴(lài)工程必須是maven中心包管理范圍內(nèi)的。如果碰上非開(kāi)源包,maven支持不了這個(gè)包,那么則有三種方法處理:1.本地安裝這個(gè)插件install plugin例如:
          mvn install:install-file -Dfile=non-maven-proj.jar -DgroupId=some.group -DartifactId=non-maven-proj -Dversion=1
          

          2.創(chuàng)建自己的Repositories并且部署這個(gè)包,使用類(lèi)似上面的deploy:deploy-file 命令3.設(shè)置scope為system,并且指定系統(tǒng)路徑

          dependency里面的classifier,用于區(qū)分從同一個(gè)pom編譯出來(lái)的但是內(nèi)容不同的同名包,例如同一個(gè)工程編譯出兩個(gè)artifact,一個(gè)支持jdk1.5一個(gè)支持jdk1.4,那么就可以使用這個(gè)來(lái)命名為jdk15和jdk14來(lái)區(qū)分,它如果出現(xiàn)在包名中,那么它必須跟在版本號(hào)后。還有一種情況是將一個(gè)工程的一些次要artifact附到主要artifact中,就可以使用這個(gè)來(lái)區(qū)分,例如一個(gè)工程產(chǎn)生source,javadoc,class三種東西,那么就可以使用不同的classifier來(lái)分別標(biāo)識(shí)這些東西
          dependency里面的type,默認(rèn)為jar,類(lèi)型,常用如:jar,ejb-client,test-jar,可以設(shè)置plugins中的extensions值為true后在增加新類(lèi)型
          dependency里面的scope,指定classpath,可以為:compile(默認(rèn)的,compile scope在所有classpaths內(nèi)有效,這些dependencies將會(huì)傳播到項(xiàng)目中。provided:指示jdk或者某個(gè)容器可以提供他,它只在compilation和test的classpaths有效,而且不會(huì)傳播的。runtime:指示這個(gè)dependency在編譯過(guò)程是不必要的,但是執(zhí)行需要,在test和runtime的classpaths有效,在compile的classpaths無(wú)效。test:指示這個(gè)dependency在一般程序運(yùn)行是無(wú)效的,但是在test的compilation和execution是有效的,system則跟provided類(lèi)似,但是這種dependency必須人工明確地制定。這種依賴(lài)不會(huì)在repository中查找。
          dependency里面的systemPath:只在dependency的scope聲明為system的時(shí)候才有用除,否則,build的過(guò)程將會(huì)失敗。路徑必須是絕對(duì)的,所以最好使用property來(lái)聲明機(jī)器的特定路徑。
          dependency里面的optional:如果工程本身是一個(gè)dependency那么就標(biāo)記為optional,例如X需要A,A需要B,那么X只需要optional的B,則B在X中就是optional聲明的了
          dependency里面的exclusions:如果X需要A,A包含B依賴(lài),那么X可以聲明不要B依賴(lài),只要在exclusions中聲明exclusion。optional是不會(huì)install或者使用B,而exclusion是將B從依賴(lài)樹(shù)中是刪除。例如appfuse不想使用hibernate,但是appfuse是集成hibernate的,所以就排除掉:
                      <exclusions>
                          <exclusion>
                              <groupId>org.appfuse</groupId>
                              <artifactId>appfuse-hibernate</artifactId>
                          </exclusion>
                      </exclusions>-->

          <!--Inheritance:如果一個(gè)工程是pareent或者aggregation(即mutil-module的)的,那么必須在packaging賦值pom。child工程從parent繼承的包括:dependencies,developers and contributors,plugin lists,reports lists,plugin execution with matching ids,plugin configuration-->
          <parent>...</parent> <!--參照下面例子:relativePath是可選的,maven會(huì)首先搜索這個(gè)地址,在搜索本地和遠(yuǎn)程repositories之前
            <parent>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>my-parent</artifactId>
              <version>2.0</version>
              <relativePath>../my-parent</relativePath>
            </parent>
          -->
           <dependencyManagement>...</dependencyManagement>  <!--用于幫助管理children的dependencies。例如如果parent使用dependencyManagement定義一個(gè)dependencyon junit:junit:4.0,那么它的children就可以只引用groupId和artifactId,而version就可以通過(guò)parent來(lái)設(shè)置。好處就是集中管理依賴(lài)詳情-->
          <modules>...</modules><!--對(duì)于多模塊project,outer-module沒(méi)有必要考慮inner-module的dependencies,當(dāng)列出modules的時(shí)候。modules的順序是不重要的,因?yàn)閙aven會(huì)自動(dòng)根據(jù)依賴(lài)關(guān)系來(lái)拓?fù)渑判?,modules例子:
              <module>my-project<module>
              <module>another-project<module>
          -->
          <properties>...</properties> <!--參照http://www.aygfsteel.com/jianyue/articles/maven2_setting.html,是一樣的-->
          <!-- Build Settings --><build>...</build> <!--
          defaultGoal默認(rèn)的目標(biāo),必須跟命令行上的參數(shù)相同例如jar:jar,或者與時(shí)期(parse)相同,例如install
          directory指定build target目標(biāo)的目錄,默認(rèn)為${basedir}/target,即項(xiàng)目根目錄下的target
          finalName指定去掉后綴名后的工程名字,例如:默認(rèn)為${artifactId}-${version}
          filters:用于定義指定filter屬性文件位置,例如filter元素賦值filters/filter1.properties,那么這個(gè)文件里面就可以定義name=value對(duì),這個(gè)name=value對(duì)的值就可以在工程pom中通過(guò)${name}引用,默認(rèn)的filter目錄是${basedir}/src/main/filters/
          resources描述工程中資源的位置
                <resource>
                  <targetPath>META-INF/plexus</targetPath>
                  <filtering>false</filtering>
                  <directory>${basedir}/src/main/plexus</directory>
                  <includes>
                    <include>configuration.xml</include>
                  </includes>
                  <excludes>
                    <exclude>**/*.properties</exclude>
                  </excludes>
                </resource>
          targetPath:指定build資源到哪個(gè)目的目錄,默認(rèn)是base directory
          filtering:指定是否將filter文件(即上面說(shuō)的filters里定義的*.property文件)的變量值在這個(gè)resource文件有效,例如上面就指定那些變量值在configuration文件無(wú)效
          directory:指定屬性文件的目錄,build的過(guò)程需要找到它,并且將其放到targetPath下。默認(rèn)的directory是${basedir}/src/main/resources
          includes:指定包含文件的patterns,符合樣式并且在directory目錄下的文件將會(huì)是包含進(jìn)project的資源文件
          excludes:指定不包含在內(nèi)的patterns,如果includes與excludes有沖突,那么excludes勝利,那些符合沖突樣式的文件還是不會(huì)包含進(jìn)來(lái)的
          testResources這個(gè)模塊包含測(cè)試資源元素,其內(nèi)容定義與resources類(lèi)似。不同的一點(diǎn)是默認(rèn)的測(cè)試資源路徑是${basefir}/src/test/resources,測(cè)試資源是不部署的。
          -->
          <plugins>...</plugins> <!--
          <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-jar-plugin</artifactId>
                  <version>2.0</version>
                  <extensions>false</extensions>
                  <inherited>true</inherited>
                  <configuration>
                    <classifier>test</classifier>
                  </configuration>
                  <dependencies>...</dependencies>
                  <executions>...</executions>
                </plugin>

          extensions:true or false,決定是否要load這個(gè)plugin的extensions
          inherited:是否讓子pom繼承true or false
          configuration:通常用于私有不開(kāi)源的plugin,不能夠詳細(xì)了解plugin的內(nèi)部工作原理,但使plugin滿足需要滿足的properties
          dependencies:與pom基礎(chǔ)的dependencies的結(jié)構(gòu)和功能都相同,只是plugin的dependencies用于plugin,而pom的dependencies用于本身這個(gè)工程,在plugin的dependencies主要用于改變plugin原來(lái)的dependencies,例如排除一些用不到的dependency或者修改dependency的版本等,詳細(xì)請(qǐng)看pom基礎(chǔ)的dependencies
          executions:plugin也有很多個(gè)目標(biāo),每個(gè)目標(biāo)具有不同的配置,executions就是設(shè)定plugin的目標(biāo)
                    <execution>
                      <id>echodir</id>
                      <goals>
                        <goal>run</goal>
                      </goals>
                      <phase>verify</phase>
                      <inherited>false</inherited>
                      <configuration>
                        <tasks>
                          <echo>Build Dir: ${project.build.directory}</echo>
                        </tasks>
                      </configuration>
                    </execution>
          id:標(biāo)識(shí)符
          goals:里面列出一系列的goal元素,例如上面的run goal
          phase:聲明goals執(zhí)行的時(shí)期,例如:verify
          inherited:是否傳遞execution到子pom
          configuration:設(shè)置execution下列表的goals 的設(shè)置,而不是plugin所有g(shù)oals的設(shè)置
          plugin Management: 用于管理plugin,與pom build里的plugins區(qū)別是,這里的plugin是列出來(lái),然后讓子pom來(lái)決定是否引用的,例如后面的引用方法。
          <pluginManagement>
                <plugins>
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.2</version>
                    <executions>
                      <execution>
                        <id>pre-process-classes</id>
                        <phase>compile</phase>
                        <goals>
                          <goal>jar</goal>
                        </goals>
                        <configuration>
                          <classifier>pre-process</classifier>
                        </configuration>
                      </execution>
                    </executions>
                  </plugin>
                </plugins>
              </pluginManagement>
          子pom引用方法:
          在pom的build里的plugins引用:
              <plugins>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-jar-plugin</artifactId>
                </plugin>
              </plugins>
          build 里面的Directories
              <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
              <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory>
              <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
              <outputDirectory>${basedir}/target/classes</outputDirectory>
              <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
          這幾個(gè)元素只在parent bulid element里面定義,他們?cè)O(shè)置多種路徑結(jié)構(gòu),他們并不在profile里,所以不能通過(guò)profile來(lái)修改
          build 里面的Extensions
          它們是一系列build過(guò)程中要使用的產(chǎn)品,他們會(huì)包含在running bulid‘s classpath里面。他們可以開(kāi)啟extensions,也可以通過(guò)提供條件來(lái)激活plugins。簡(jiǎn)單來(lái)講,extensions是在build過(guò)程被激活的產(chǎn)品
              <extensions>
                <extension>
                  <groupId>org.apache.maven.wagon</groupId>
                  <artifactId>wagon-ftp</artifactId>
                  <version>1.0-alpha-3</version>
                </extension>
              </extensions>
          -->
           <reporting>...</reporting> <!--
          reporting包含site生成階段的一些元素,某些maven  plugin可以生成reports并且在repoting下配置。例如javadoc,maven site等,在reporting下配置reprot plugin的方法與build幾乎一樣,最不同的是:build的plug-in goals在executions下設(shè)置,而reporting的configures goals在reportset。更微妙的不同是reporting下的plugin configuration works as a build plugin configuration,但是相反是不對(duì)的(即build plugin configuration does not affect a reporting plugin)。
          excludeDefaults:是否排除site generator默認(rèn)產(chǎn)生的reports
          outpoutDirectory,默認(rèn)的dir變成:${basedir}/target/site
          Report sets:設(shè)置execution goals,相當(dāng)于build里面的executions。不同的是不能夠bind a report to another phase,只能夠是site
          <reporting>
              <plugins>
                <plugin>
                  ...
                  <reportSets>
                    <reportSet>
                      <id>sunlink</id>
                      <reports>
                        <report>javadoc</report>
                      </reports>
                      <inherited>true</inherited>
                      <configuration>
                        <links>
                          <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
                        </links>
                      </configuration>
                    </reportSet>
                  </reportSets>
                </plugin>
              </plugins>
            </reporting>
          reporting里面的厄reportSets和build里面的executions的作用都是控制pom的不同粒度去控制build的過(guò)程,我們不單要配置plugins,還要配置那些plugins單獨(dú)的goals。
          -->
          <!-- More Project Information -->
          <description>...</description>
          project的描述
          <inceptionYear>...</inceptionYear>
          工程的初始時(shí)間
          <licenses>...</licenses>
          <licenses>
            <license>
              <name>Apache 2</name>
              <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
              <distribution>repo</distribution>
              <comments>A business-friendly OSS license</comments>
            </license>
          </licenses>
          <!--列出本工程直接的licenses,而不要列出dependencies的licenses,

        1. name, url and comments: are self explanatory, and have been encountered before in other capacities. The fourth license element is:
        2. distribution: This describes how the project may be legally distributed. The two stated methods are repo (they may be downloaded from a Maven repository) or manual (they must be manually installed).

          -->
          <organization>...</organization>
          <!--
             <organization>
              <name>Codehaus Mojo</name>
              <url>http://mojo.codehaus.org</url>
            </organization>
          很多工程都受到某些組織運(yùn)行,這里設(shè)置基本信息
          -->
          <developers>...</developers>
          <!--例如:一個(gè)開(kāi)發(fā)者可以有多個(gè)roles,properties是
            <developers>
              <developer>
                <id>eric</id>
                <name>Eric</name>
                <email>eredmond@codehaus.org</email>
                <url>http://eric.propellors.net</url>
                <organization>Codehaus</organization>
                <organizationUrl>http://mojo.codehaus.org</organizationUrl>
                <roles>
                  <role>architect</role>
                  <role>developer</role>
                </roles>
                <timezone>-6</timezone>
                <properties>
                  <picUrl>http://tinyurl.com/prv4t</picUrl>
                </properties>
              </developer>
            </developers>
          -->
          <contributors>...</contributors>
          <!--跟developer差不多,只是contributors是副的工作人員,不過(guò)良好工程應(yīng)該需要更多的contributors而不是developer,例如:
            <contributors>
              <contributor>
                <name>Noelle</name>
                <email>some.name@gmail.com</email>
                <url>http://noellemarie.com</url>
                <organization>Noelle Marie</organization>
                <organizationUrl>http://noellemarie.com</organizationUrl>
                <roles>
                  <role>tester</role>
                </roles>
                <timezone>-5</timezone>
                <properties>
                  <gtalk>some.name@gmail.com</gtalk>
                </properties>
              </contributor>
            </contributors>
          -->
          <!-- Environment Settings --> <issueManagement>...</issueManagement>
           <!--定義defect tracking system缺陷跟蹤系統(tǒng),比如有(bugzilla,testtrack,clearquest等),例如:
            <issueManagement>
              <system>Bugzilla</system>
              <url>http://127.0.0.1/bugzilla/</url>
            </issueManagement>
          -->
          <ciManagement>...</ciManagement>
          <!--Continuous Integration Management:設(shè)置自動(dòng)build系統(tǒng),一些集成程序包括continuum,Cruise control等。例如:

          <ciManagement>
              <system>continuum</system>
              <url>http://127.0.0.1:8080/continuum</url>
              <notifiers>
                <notifier>
                  <type>mail</type>
                  <sendOnError>true</sendOnError>
                  <sendOnFailure>true</sendOnFailure>
                  <sendOnSuccess>false</sendOnSuccess>
                  <sendOnWarning>false</sendOnWarning>
                  <configuration><address>continuum@127.0.0.1</address></configuration>
                </notifier>
              </notifiers>
            </ciManagement>

          maven捕獲一些經(jīng)常重發(fā)生的配置,在notifier元素里配置。A notifier is the manner in which people are notified of certain build statuses. In the following example, this POM is setting a notifier of type mail (meaning email), and configuring the email address to use on the specified triggers sendOnError, sendOnFailure, and not sendOnSuccess or sendOnWarning.
          -->
          <mailingLists>...</mailingLists>
          <!--例如:
            <mailingLists>
              <mailingList>
                <name>User List</name>
                <subscribe>user-subscribe@127.0.0.1</subscribe>
                <unsubscribe>user-unsubscribe@127.0.0.1</unsubscribe>
                <post>user@127.0.0.1</post>
                <archive>http://127.0.0.1/user/</archive>
                <otherArchives>
                  <otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive>
                </otherArchives>
              </mailingList>
            </mailingLists>
          看不懂解釋啊,照搬吧:

        3. subscribe, unsubscribe: There elements specify the email addresses which are used for performing the relative actions To subscribe to the user list above, a user would send an email to user-subscribe@127.0.0.1.
        4. archive: This element specifies the url of the archive of old mailing list emails, if one exists. If there are mirrored archives, they can be specified under otherArchives.
        5. post: The email address which one would use in order to post to the mailing list. Note that not all mailing lists have the ability to post to (such as a build failure list).
          -->
          <scm>...</scm>

          <!--例如:
            <scm>
              <connection>scm:svn:http://127.0.0.1/svn/my-project</connection>
              <developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection>
              <tag>HEAD</tag>
              <url>http://127.0.0.1/websvn/my-project</url>
            </scm>
          connection, developerConnection: 都是連接字符串,其中后者是具有write權(quán)限的scm連接,常用的scm工具包括cvs與subversion,還有其他scms,url的字符串格式是:scm:[provider]:[provider_specific],例如cvs的是scm:cvs:pserver:127.0.0.1:/cvs/root:my-project
          tag:說(shuō)明project所在的目錄tag,默認(rèn)是HEAD,表示根目錄
          url:公開(kāi)的可瀏覽repository
          -->

          <prerequisites>...</prerequisites>
           <!--首要條件,如果不滿足,maven會(huì)在事件開(kāi)始之前失敗,在pom4.0,唯一的首要條件是maven元素-->
          <repositories>...</repositories>
          <!--要成為maven2的repository artifact,必須具有pom文件在$BASE_REPO/groupId/artifactId/version/artifactId-version.pom
          BASE_REPO可以是本地,也可以是遠(yuǎn)程的。repository元素就是聲明那些去查找的repositories
          默認(rèn)的central Maven repository在http://repo1.maven.org/maven2/
          <repositories>
              <repository>
                <releases>
                  <enabled>false</enabled>
                  <updatePolicy>always</updatePolicy>
                  <checksumPolicy>warn</checksumPolicy>
                </releases>
                <snapshots>
                  <enabled>true</enabled>
                  <updatePolicy>never</updatePolicy>
                  <checksumPolicy>fail</checksumPolicy>
                </snapshots>
                <id>codehausSnapshots</id>
                <name>Codehaus Snapshots</name>
                <url>http://snapshots.maven.codehaus.org/maven2</url>
                <layout>default</layout>
              </repository>
            </repositories>
          release和snapshots:是artifact的兩種policies,pom可以選擇那種政策有效。
          enable:本別指定兩種類(lèi)型是否可用,true or false
          updatePolicy:說(shuō)明更新發(fā)生的頻率always 或者 never 或者 daily(默認(rèn)的)或者 interval:X(X是分鐘數(shù))
          checksumPolicy:When Maven deploys files to the repository, it also deploys corresponding checksum files. Your options are to ignore, fail, or warn on missing or incorrect checksums.
          layout:maven1.x與maven2有不同的layout,所以可以聲明為default或者是legacy(遺留方式maven1.x)。
          -->
           <pluginRepositories>...</pluginRepositories>
          <!--與Repositories具有類(lèi)似的結(jié)構(gòu),只是Repositories是dependencies的home,而這個(gè)是plugins 的home。-->
          <distributionManagement>...</distributionManagement>
          <!--管理distribution和supporting files。
          downloadUrl:是其他項(xiàng)目為了抓取本項(xiàng)目的pom’s artifact而指定的url,就是說(shuō)告訴pom upload的地址也就是別人可以下載的地址。
          status:這里的狀態(tài)不要受到我們的設(shè)置,maven會(huì)自動(dòng)設(shè)置project的狀態(tài),有效的值:none:沒(méi)有聲明狀態(tài),pom默認(rèn)的;converted:本project是管理員從原先的maven版本convert到maven2的;partner:以前叫做synched,意思是與partner repository已經(jīng)進(jìn)行了同步;deployed:至今為止最經(jīng)常的狀態(tài),意思是制品是從maven2 instance部署的,人工在命令行deploy的就會(huì)得到這個(gè);verified:本制品已經(jīng)經(jīng)過(guò)驗(yàn)證,也就是已經(jīng)定下來(lái)了最終版。
          repository:聲明deploy過(guò)程中current project會(huì)如何變成repository,說(shuō)明部署到repository的信息。
              <repository>
                <uniqueVersion>false</uniqueVersion>
                <id>corp1</id>
                <name>Corporate Repository</name>
                <url>scp://repo1/maven2</url>
                <layout>default</layout>
              </repository>
              <snapshotRepository>
                <uniqueVersion>true</uniqueVersion>
                <id>propSnap</id>
                <name>Propellors Snapshots</name>
                <url>sftp://propellers.net/maven</url>
                <layout>legacy</layout>
              </snapshotRepository>
          id, name::唯一性的id,和可讀性的name
          uniqueVersion:指定是否產(chǎn)生一個(gè)唯一性的version number還是使用address里的其中version部分。true or false
          url:說(shuō)明location和transport protocol
          layout:default或者legacy-->
          <site><!---聲明如何部署project‘s 的site和document->
          <!--例如:
              <site>
                <id>mojo.website</id>
                <name>Mojo Website</name>
                <url>scp://beaver.codehaus.org/home/projects/mojo/public_html/</url>
              </site>
          與上面repository的元素相同意思
          -->
          Relocation
          <!-- 說(shuō)明工程的變更,在這里警告使用者當(dāng)心工程被重命名了等信息。重新指定id和名稱(chēng),并且寫(xiě)個(gè)message注明備注   <relocation>
                <groupId>org.apache</groupId>
                <artifactId>my-project</artifactId>
                <version>1.0</version>
                <message>We have moved the Project under Apache</message>
              </relocation>
          -->
          <profiles>...</profiles>
          <!--pom4.0的一個(gè)新特性就是具有根據(jù)environment來(lái)修改設(shè)置的能力。

        6. 它包含可選的activation(profile的觸發(fā)器)和一系列的changes。例如test過(guò)程可能會(huì)指向不同的數(shù)據(jù)庫(kù)(相對(duì)最終的deployment)或者不同的dependencies或者不同的repositories,并且是根據(jù)不同的JDK來(lái)改變的。那么結(jié)構(gòu)如下:

            <profiles>
              <profile>
                <id>test</id>
                <activation>...</activation>
                <build>...</build>
                <modules>...</modules>
                <repositories>...</repositories>
                <pluginRepositories>...</pluginRepositories>
                <dependencies>...</dependencies>
                <reporting>...</reporting>
                <dependencyManagement>...</dependencyManagement>
                <distributionManagement>...</distributionManagement>
              </profile>
            </profiles>
          Activation
          觸發(fā)這個(gè)profile的條件配置如下例:(只需要其中一個(gè)成立就可以激活profile,如果第一個(gè)條件滿足了,那么后面就不會(huì)在進(jìn)行匹配。
              <profile>
                <id>test</id>
                <activation>
                  <activeByDefault>false</activeByDefault>
                  <jdk>1.5</jdk>
                  <os>
                    <name>Windows XP</name>
                    <family>Windows</family>
                    <arch>x86</arch>
                    <version>5.1.2600</version>
                  </os>
                  <property>
                    <name>mavenVersion</name>
                    <value>2.0.3</value>
                  </property>
                  <file>
                    <exists>${basedir}/file2.properties</exists>
                    <missing>${basedir}/file1.properties</missing>
                  </file>
                </activation>

          -->
          激活profile的方法有多個(gè):setting文件的activeProfile元素明確指定激活的profile的ID,在命令行上明確激活Profile用-P flag 參數(shù)
          查看某個(gè)build會(huì)激活的profile列表可以用:mvn help:active-profiles
          </project>


          評(píng)論

          # re: maven pom.xml詳解  回復(fù)  更多評(píng)論   

          2013-04-15 18:17 by feilian09
          學(xué)習(xí)……

          # re: maven pom.xml詳解  回復(fù)  更多評(píng)論   

          2014-12-24 17:53 by 糖先生
          好文章~

          # re: maven pom.xml詳解  回復(fù)  更多評(píng)論   

          2015-04-30 15:54 by zuidaima
          可以參考最新的文檔:
          如何在eclipse jee中檢出項(xiàng)目并轉(zhuǎn)換為Maven project,最后轉(zhuǎn)換為Dynamic web project,地址:http://zuidaima.com/blog/1618180875144192.htm
          如何在eclipse jee中創(chuàng)建Maven project并且轉(zhuǎn)換為Dynamic web project
          地址:http://zuidaima.com/blog/1618162161323008.htm

          # re: maven pom.xml詳解  回復(fù)  更多評(píng)論   

          2015-08-05 13:24 by zuidaima
          史上最全的maven pom.xml文件教程詳解 http://zuidaima.com/share/1781583829978112.htm

          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 南通市| 罗源县| 平阳县| 枣庄市| 水富县| 原阳县| 共和县| 兴山县| 赤峰市| 凯里市| 佛坪县| 忻州市| 资兴市| 曲靖市| 普格县| 墨脱县| 汉沽区| 铁岭市| 宜兰市| 易门县| 乐至县| 临安市| 台中市| 德昌县| 徐州市| 陇川县| 大宁县| 瑞丽市| 乐陵市| 浑源县| 汉川市| 临泽县| 永州市| 富平县| 虹口区| 湖南省| 永登县| 秦皇岛市| 全州县| 阿拉尔市| 通州市|