我看的書籍是<Ant權(quán)威指南>,Ant的開發(fā)者:James Duncan Davidson。對于一些比較重要的內(nèi)容我記錄了下來:
ANT命令行參考
ant [option [option...]] [target [target...]]
option :={-help:顯示描述Ant命令及其選項(xiàng)的幫助信息
-projecthelp:顯示包含在構(gòu)建文件中的、所有用戶編寫的幫助文檔。即為各個<target>中description屬 性的文本,以及包含在<description>元素中的任何文本。將有description屬性的目標(biāo)列為主目標(biāo)("Main target"),沒有此屬性的目標(biāo)則列為子目標(biāo)("subtarget")
-version:要求Ant顯示其版本信息,然后退出
-quiet:抑制并非由構(gòu)建文件中的echo任務(wù)所產(chǎn)生的大多數(shù)信息
-verbose:顯示構(gòu)建過程中每個操作的詳細(xì)消息。此選項(xiàng)與-debug選項(xiàng)只能選其一
-debug:顯示Ant和任務(wù)開發(fā)人員已經(jīng)標(biāo)志為調(diào)試消息的消息。此選項(xiàng)與-verbose只能選其一
-emacs:對日志消息進(jìn)行格式化,使它們能夠很容易地由Emacs的shell模式(shell-mode)所解析;也就是說,打印任務(wù)事件,但并不縮排,在其之前也沒有[taskname]
-logfile filename:將日志輸出重定向到指定文件
-logger classname:指定一個類來處理Ant的日志記錄。所指定的類必須實(shí)現(xiàn)了org.apache.tools.ant.BuildLogger接口
-listener classname:為Ant聲明一個監(jiān)聽類,并增加到其監(jiān)聽者列表中。在Ant與IDE或其他Java程序集成時,此選項(xiàng)非常有用
-buildfile filename:指定Ant需要處理的構(gòu)建文件。默認(rèn)的構(gòu)建文件為build.xml
-Dproperty=value:在命令行上定義一個特性名--值對
-find filename:指定Ant應(yīng)當(dāng)處理的構(gòu)建文件。與-buildfile選項(xiàng)不同,如果所指定文件在當(dāng)前目錄中未找到,-find就要求Ant在其父目錄中再進(jìn)行搜索。這種搜索會繼續(xù)在其祖父目錄中進(jìn)行,直至達(dá)到文件系統(tǒng)的根為止,在此如果文件還未找到,則構(gòu)建失敗
}
compile
,test
,provided,runtime,test,system
compile
是默認(rèn)的范圍;如果沒有提供一個范圍,那該依賴的范圍就是編譯范圍。編譯范圍依賴在所有的classpath中可用,同時它們也會被打包。
provided
依賴只有在當(dāng)JDK或者一個容器已提供該依賴之后才使用。例如,如果你開發(fā)了一個web應(yīng)用,你可能在編譯classpath中需要可用的Servlet API來編譯一個servlet,但是你不會想要在打包好的WAR中包含這個Servlet API;這個Servlet API JAR由你的應(yīng)用服務(wù)器或者servlet容器提供。已提供范圍的依賴在編譯classpath(不是運(yùn)行時)可用。它們不是傳遞性的,也不會被打包。
runtime
依賴在運(yùn)行和測試系統(tǒng)的時候需要,但在編譯的時候不需要。比如,你可能在編譯的時候只需要JDBC API JAR,而只有在運(yùn)行的時候才需要JDBC驅(qū)動實(shí)現(xiàn)。
test
范圍依賴在一般的 編譯和運(yùn)行時都不需要,它們只有在測試編譯和測試運(yùn)行階段可用。
system
范圍依賴與provided
類似,但是你必須顯式的提供一個對于本地系統(tǒng)中JAR文件的路徑。這么做是為了允許基于本地對象編譯,而這些對象是系統(tǒng)類庫的一部分。這樣的構(gòu)件應(yīng)該是一直可用的,Maven也不會在倉庫中去尋找它。如果你將一個依賴范圍設(shè)置成系統(tǒng)范圍,你必須同時提供一個systemPath
元素。注意該范圍是不推薦使用的(你應(yīng)該一直盡量去從公共或定制的Maven倉庫中引用依賴)。
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>[3.8,4.0)</version> <scope>test</scope> </dependency>
<major version>.<minor version>.<incremental version>-<qualifier>Maven提供了三個隱式的變量,可以用來訪問環(huán)境變量,POM信息,和Maven Settings.
env
變量:暴露了你操作系統(tǒng)或者shell的環(huán)境變量
project
變量暴露了POM。
settings
變量暴露了Maven settings信息。
<properties> <foo>bar</foo> </properties>
超級POM
所有的Maven項(xiàng)目的POM都擴(kuò)展自超級POM。你可以在${M2_HOME}/lib
中的maven-2.0.9-uber.jar
文件中找到pom-4.0.0.xml
。
超級pom:
<project>
<modelVersion>4.0.0</modelVersion>
<name>Maven Default Project</name>
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>http://repo1.maven.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<finalName>content-zh-0.5</finalName>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-1</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.1</version>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-rar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-7</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>2.0-beta-6</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.0.4</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-1</version>
</plugin>
</plugins>
</pluginManagement>
<reporting>
<outputDirectory>target/site</outputDirectory>
</reporting>
</project>
1).默認(rèn)的超級POM定義了一個單獨(dú)的遠(yuǎn)程Maven倉庫,ID為central,這是所有Maven客戶端默認(rèn)配置訪問的中央Maven倉庫;該配置可以通過一個自定義的
settings.xml
文件來覆蓋,注意這個默認(rèn)的超級POM關(guān)閉了從中央Maven倉庫下載snapshot構(gòu)件的功能。如果你需要使用一個snapshot倉庫,你就要在你的pom.xml
或者settings.xml
中自定義倉庫設(shè)置.
2)build
元素設(shè)置Maven標(biāo)準(zhǔn)目錄布局中那些目錄的默認(rèn)值.
3)POM中定義的groupId
,artifactId
和version
:這三項(xiàng)是所有項(xiàng)目都需要的坐標(biāo)
一個groupId
歸類了一組相關(guān)的構(gòu)件。組定義符基本上類似于一個Java包名。例如:groupId
org.apache.maven
是所有由Apache Maven項(xiàng)目生成的構(gòu)件的基本groupId。組定義符在Maven倉庫中被翻譯成路徑,例如,groupId
org.apache.maven
可以在repo1.maven.org的/maven2/org/apache/maven
目錄下找到。
artifactId
是項(xiàng)目的主要定義符。當(dāng)你生成一個構(gòu)件,這個構(gòu)件將由artifactId
命名。當(dāng)你引用一個項(xiàng)目,你就需要使用artifactId
來引用它。artifactId
和groupId
的組合必須是唯一的。換句話說,你不能有兩個不同的項(xiàng)目擁有同樣的artifactId
和groupId
;在某個特定的groupId
下,artifactId
也必須是唯一的。
當(dāng)一個構(gòu)件發(fā)布的時候,它是使用一個版本號發(fā)布的。該版本號是一個數(shù)字定義符如“1.0”,“1.1.1”,或“1.1.2-alpha-01”。你也可以使用所謂的快照(snapshot)版本。一個快照版是一個處于開發(fā)過程中的組件的版本,快照版本號通常以SNAPSHOT結(jié)尾;如,“1.0-SNAPSHOT”,“1.1.1-SNAPSHOT”,和“1-SNAPSHOT”。Section 9.3.1, “項(xiàng)目版本”介紹了版本和版本界限。