maven簡(jiǎn)介
Maven
Maven簡(jiǎn)介
Maven最初的目的是在Jakarta Turbine項(xiàng)目中使構(gòu)建處理簡(jiǎn)單化。幾個(gè)項(xiàng)目之間使用到的Ant build文件差異很小,各個(gè)JAR都存入CVS。因此希望有一個(gè)標(biāo)準(zhǔn)的方法構(gòu)建各個(gè)工程,清晰的定義一個(gè)工程的組成,一個(gè)容易的方法去發(fā)布項(xiàng)目信息并且去提供一種在各個(gè)項(xiàng)目之間共享JAR包。
結(jié)果出現(xiàn)了一種功能能用于構(gòu)建和管理任何基于java的工程。Maven小組希望他們已經(jīng)做到了一些事情,這將有助于Java開發(fā)者更容易的完成每天的工作并且有助于理解任何基于java的項(xiàng)目。
Maven的目標(biāo)是:
-
使構(gòu)建過程更容易
-
提供統(tǒng)一構(gòu)建系統(tǒng)
-
提供高質(zhì)量的項(xiàng)目信息
-
提供開發(fā)的最佳實(shí)踐指南
-
能無縫的加入新的特性
對(duì)Maven的錯(cuò)誤理解
-
Maven是一個(gè)站點(diǎn)和文檔制作工具。
-
Maven擴(kuò)展了Ant,使其能下載到各種依賴包
-
Maven是一系列可重用的Ant腳本
Maven的版本。
Maven現(xiàn)在主要有Maven 1.x和Maven 2.x,其中現(xiàn)在最新版本是Maven 2.02。
Maven 2完成了對(duì)Maven 1的重寫。重寫的首要目的是要提供了強(qiáng)大的Jave構(gòu)建和包含API的項(xiàng)目,允許Maven被植入任何地方,尤其是高級(jí)別的產(chǎn)品如IDEs、質(zhì)量工具、報(bào)告工具等這些。Maven 2構(gòu)建生命周期的概念正式化,其比Maven更易擴(kuò)展。
因此現(xiàn)在我們主要研究的就是Maven 2。
Maven的安裝
-
Windows 2000/xp下的安裝
-
解壓縮maven-2.0.2-bin.zip到你希望安裝Maven 2.0.2的所在目錄。這里假設(shè)你選擇了C:\ProgramFiles\Apache Software Foundation\maven-2.0.2.
-
將C:\Program Files\Apache Software Foundation\maven-2.0.2\bin目錄加入到你的%path%環(huán)境變量中。
-
同時(shí),確認(rèn)JAVA_HOME是否正確設(shè)置成功。
-
運(yùn)行 mvn --version 確認(rèn)是否安裝成功。
-
顯示Maven version: 2.0.2 則表示安裝成功。
-
基于Unxi-based的操作系統(tǒng)(Linux,Solaris and Mac OS X)
-
解壓縮發(fā)布包到你希望安裝Maven 2.0.2的所在目錄。這里假設(shè)你選擇了/usr/local/maven-
-
將/usr/local/maven-2.0.2/bin目錄加入到你的path環(huán)境變量中,例如:PATH=/usr/local/maven-2.0.2y/bin: $PATH。
-
同時(shí),確認(rèn)JAVA_HOME是否正確設(shè)置成功。
-
運(yùn)行 mvn --version 確認(rèn)是否安裝成功。
-
顯示Maven version: 2.0.2 則表示安裝成功。
Maven主要功能列表
Maven是一種對(duì)項(xiàng)目的管理工具,它提供了一種方式來管理以下項(xiàng)目中涉及到的工作內(nèi)容,同時(shí)以下也是Maven的主要功能:
-
構(gòu)建項(xiàng)目(Builds)
-
文檔編制(Documentation)
-
報(bào)告(Reporting)
-
依賴管理(Dependencies)
-
配置管理(SCMs)
-
發(fā)布管理(Releases)
構(gòu)建項(xiàng)目
-
首先創(chuàng)建一個(gè)Maven工程
Maven可用于構(gòu)建java應(yīng)用工程和java web應(yīng)用工程。
-
WebApp
mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp
-DarchetypeArtifactId=maven-archetype-webapp
my-webapp
|-- pom.xml
`-- src
`-- main
|-- webapp
| |-- WEB-INF
| | `-- web.xml
| `--index.jsp
`-- resources
其他的目錄則需要自己補(bǔ)充。
其pom.xml文件內(nèi)容如下:
-
<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.mycompany.app</groupId>
<artifactId>my-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Webapp Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>my-webapp</finalName>
</build>
</project>
-
App
mvn archetype:create -DgroupId=com.mycompany.ap -DartifactId=my-app
命令正確執(zhí)行后,生成如下目錄:
my-app
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- com
| `-- mycompany
| `-- app
| `-- App.java
`-- test
`-- java
`-- com
`-- mycompany
`-- app
`-- AppTest.java
其pom.xml文件內(nèi)容如下:
-
<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.mycompany.ap</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
-
Maven項(xiàng)目的標(biāo)準(zhǔn)目錄介紹
Maven提倡使用一個(gè)共同的標(biāo)準(zhǔn)目錄結(jié)構(gòu),使開發(fā)人員能在熟悉了一個(gè)Maven工程后,對(duì)其他的Maven工程也能清晰了解。這樣做也省去了很多設(shè)置的麻煩。
以下的文檔介紹是Maven希望的目錄結(jié)構(gòu),并且也是目錄創(chuàng)建工程是采用的目錄結(jié)構(gòu)。Maven推薦大家盡可能的遵守這樣的目錄結(jié)構(gòu)。
src/main/java |
Application/Library sources |
src/main/resources |
Application/Library resources |
src/main/filters |
Resource filter files |
src/main/assembly |
Assembly descriptors |
src/main/config |
Configuration files |
src/main/webapps |
Web application sources |
src/test/java |
Test sources |
src/test/resources |
Test resources |
src/test/filters |
Test resource filter files |
src/site |
Site |
LICENSE.txt |
Project's license |
README.txt |
Project's readme |
在頂級(jí)目錄上是工程的描述文件pom.xml(如果使用Ant則還包括其他屬性文件,maven.xml或build.xml),另外還包括提供給最終用戶的文件,如,README.txt, LICENSE.txt等等。
頂級(jí)目錄還包括兩個(gè)子目錄:src,target。頂級(jí)目錄下可能出現(xiàn)的其他目錄僅僅是CVS或.svn和其他多模塊工程的工程目錄,最好不要再有其他目錄。
Target目錄是所有工程編譯構(gòu)建的輸出目錄。
Src目錄包含所有工程的源碼文件,配置文件,資源文件等等。它下面的子目錄一般包含main(主要的工程源文件),test(測(cè)試文件),site(項(xiàng)目站點(diǎn)文件)。
-
項(xiàng)目構(gòu)建的生命周期的介紹
Maven 2是圍繞著構(gòu)建生命周期概念設(shè)計(jì)的。這意味著,構(gòu)建或者發(fā)布的過程已經(jīng)被清晰的定義了。
當(dāng)我們使用Maven構(gòu)建工程時(shí),我們只需要了解幾個(gè)Maven定義好的命令即可,其他的工作則交給POM來完成。
以下給出Maven提供的構(gòu)建生命周期列表:
validate |
validate the project is correct and all necessary information is available. |
generate-sources |
generate any source code for inclusion in compilation. |
process-sources |
process the source code, for example to filter any values. |
generate-resources |
generate resources for inclusion in the package. |
process-resources |
copy and process the resources into the destination directory, ready for packaging. |
compile |
compile the source code of the project. |
process-classes |
post-process the generated files from compilation, for example to do bytecode enhancement on Java classes. |
generate-test-sources |
generate any test source code for inclusion in compilation. |
process-test-sources |
process the test source code, for example to filter any values. |
generate-test-resources |
create resources for testing. |
process-test-resources |
copy and process the resources into the test destination directory. |
test-compile |
compile the test source code into the test destination directory |
test |
run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed. |
package |
take the compiled code and package it in its distributable format, such as a JAR. |
pre-integration-test |
perform actions required before integration tests are executed. This may involve things such as setting up the required environment. |
integration-test |
process and deploy the package if necessary into an environment where integration tests can be run. |
post-integration-test |
perform actions required after integration tests have been executed. This may including cleaning up the environment. |
verify |
run any checks to verify the package is valid and meets quality criteria. |
install |
install the package into the local repository, for use as a dependency in other projects locally. |
deploy |
done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. |
因此,當(dāng)我們構(gòu)建一個(gè)項(xiàng)目時(shí),只需要了解自己希望做什么,然后執(zhí)行以上對(duì)應(yīng)的生命周期即可。
例如,我們希望編譯我們的工程。在命令行狀態(tài)下進(jìn)入到工程的pom.xml文件所在的目錄中,使用命令:mvn compile;希望構(gòu)建打包我們的工程,使用mvn package即可。
當(dāng)然了,maven的構(gòu)建生命周期也是可以擴(kuò)展和自定義的,這里就先不做介紹了。
-
pom.xml的介紹
pom.xml包含了一個(gè)項(xiàng)目的項(xiàng)目對(duì)象模型(POM)。項(xiàng)目對(duì)象模型(POM)是Maven工作的基本單元。請(qǐng)記住,這個(gè)是非常重要的,因?yàn)?font face="宋體, SimSun">POM包含了工程的非常重要的信息塊,并且基本上包含了和項(xiàng)目相關(guān)的任何要素。
讓我們熟悉一下pom.xml包含的基本項(xiàng):
-
poject 這是pom.xml的頂級(jí)元素。
-
modelVersion 這是元素指出了這個(gè)POM使用的是那個(gè)版本的對(duì)象模型。這個(gè)模型的版本自身么是經(jīng)常改變的,但這種改變是為了使模型更加的穩(wěn)定。
-
groupId 這個(gè)元素指出創(chuàng)建這個(gè)工程的組織或團(tuán)隊(duì)的唯一標(biāo)識(shí),并且這個(gè)也是一個(gè)項(xiàng)目的關(guān)鍵標(biāo)識(shí),推薦使用這個(gè)組織或團(tuán)隊(duì)的完整域名。例如:org.apache.maven.plugins是為Maven plug-ins定義的groupId。
-
artifactId 這個(gè)元素指出這個(gè)工程的主要制品的基本名稱。一個(gè)工程的主要制品如果是jar文件,次要制品如果是源碼包,則次要制品的名稱的一部分也使用artifactId。典型的制品名稱使用這樣的格式:<artifactId>-<version>.<extension>(例如,myapp-1.0.jar)。
-
packaging 這個(gè)元素指出制品的類型(例如:JAR,WAR,EAR等等)。這個(gè)元素不僅僅指示出制品的類型,同時(shí)也指示出工程構(gòu)建過程中的部分生命周期。Packaging的默認(rèn)值是JAR。
-
version 這個(gè)元素指出這個(gè)項(xiàng)目產(chǎn)生的制品的版本號(hào),Maven在幫助開發(fā)人員管理版本號(hào)時(shí)走了很長(zhǎng)的路,以后你將經(jīng)常看到SNAPSHOT在一個(gè)版本中,這個(gè)表示一個(gè)工程仍然在開發(fā)狀態(tài)。
-
name 這個(gè)元素指出這個(gè)工程顯示的名稱。這個(gè)常用于Maven產(chǎn)生的文檔中。
-
url 這個(gè)員算指出在哪里能發(fā)現(xiàn)工程的站點(diǎn)。這個(gè)常用于Maven產(chǎn)生的文檔中。
-
desription 這個(gè)元素提供了這個(gè)工程基本的描述。這個(gè)也常用于Maven產(chǎn)生的文檔中。
以上只是pom.xml中的一些基本項(xiàng),完整的pom.xml的元素介紹請(qǐng)參考:
http://maven.apache.org/maven-model/maven.html
文檔編制
-
文檔創(chuàng)建:
對(duì)于如何創(chuàng)建和編制文檔,maven有一個(gè)簡(jiǎn)單的示例命令:
mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-site |
執(zhí)行了以上命令后,我們將得到這樣一個(gè)目錄結(jié)構(gòu):
my-app |-- pom.xml `-- src |-- site |-- apt | |-- format.apt | `-- index.apt |-- fml | `-- faq.fml |-- fr | |-- apt | | |-- format.apt | | `-- index.apt | |-- fml | | `-- faq.fml | `-- xdoc | `-- xdoc.xml |-- site.xml |-- site_fr.xml `-- xdoc `-- xdoc.xml |
你現(xiàn)在可以看到一個(gè)$basedir/src/site目錄,以及它包含的一些站點(diǎn)描述文件(site.xml,site_fr_xml),和各種maven支持的文檔格式相對(duì)應(yīng)的目錄和示例文檔都已經(jīng)產(chǎn)生。
以上的創(chuàng)建只是示例,我們自己創(chuàng)建時(shí)就沒有命令行使用了,只能按照上面的目錄結(jié)構(gòu)創(chuàng)建我們需要的文檔,并在文檔中寫入我們工程的信息。
讓我們?cè)賮砜纯?/font>maven所支持的文檔格式。
-
文檔格式:
Maven支持3種文檔格式:
-
Xdoc format
這個(gè)是一種簡(jiǎn)單快捷的,基于original Anakia format的文件格式。
-
APT format
“Almost Plain Text”,(接近普通文本格式),這是一種允許你采用接近普通文本格式的方式簡(jiǎn)單的寫出類似于wiki格式的結(jié)構(gòu)性文檔。
如果你對(duì)此很感興趣,請(qǐng)參考完整的APT format的書寫規(guī)范
http://maven.apache.org/guides/mini/guide-apt-format.html
-
FML formate
這個(gè)是一種FAQ結(jié)構(gòu)形式的文檔格式。
了解了以上的文檔格式,我們就可以按照以上文檔格式的要求,選用我們喜歡的文檔格式編寫我們的文檔。當(dāng)編寫完成后,我們需要生成所有文檔。這里生成文檔,maven的處理是生成站點(diǎn)(site),也就是身成html頁(yè)面,這樣所有對(duì)此項(xiàng)目感興趣的人員都可以通過訪問此站點(diǎn)來了解所有的信息。生成站點(diǎn)的命令是:
mvn site |
-
文檔國(guó)際化:
當(dāng)然,你可能早就想到文檔國(guó)際化的問題,這里maven也早就處理了。在pom.xml中
<project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <configuration> <locales>en,fr</locales> </configuration> </plugin> </plugins> ... |
注意到<locales>en,fr</locales>了嗎?這里就支持了英語(yǔ)(en)和法語(yǔ)(fr)兩種語(yǔ)言的文檔。請(qǐng)注意以下生成的目錄,由于英語(yǔ)是在第一個(gè),屬于默認(rèn)語(yǔ)言,所以$basedir/src/site目錄下并沒有en的文件夾,而有fr的文件夾,而且這個(gè)文件夾里包含了maven支持的文檔格式相對(duì)應(yīng)的目錄和示例文檔。
報(bào)告設(shè)置
Maven有多個(gè)報(bào)告能添加在你的文檔站點(diǎn)中,來顯示項(xiàng)目當(dāng)前的狀態(tài),這些報(bào)告采用插件的形式可在項(xiàng)目中配置。
為了為你的文檔站點(diǎn)增加這些報(bào)告,必須增加reporting部分在pom.xml中,下面這個(gè)為標(biāo)準(zhǔn)的項(xiàng)目信息報(bào)告插件在pom.xml中的配置。
<project> ... <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </plugin> </plugins> </reporting> ... |
Maven在執(zhí)行mvn site命令時(shí),除了產(chǎn)生開發(fā)人員編制的文檔信息外,根據(jù)pom.xml中設(shè)置的報(bào)告,會(huì)同時(shí)生成這個(gè)項(xiàng)目信息的報(bào)告文檔。并且這個(gè)是默認(rèn)的生成項(xiàng)。
這個(gè)默認(rèn)的生成項(xiàng)將根據(jù)項(xiàng)目的信息生成以下報(bào)告:
-
持續(xù)集成信息(Continuous Integration)
-
依賴性信息(Dependencies)
-
發(fā)布追蹤信息(Issue Tracking)
-
郵件列表信息(Mailing Lists)
-
工程協(xié)議信息(Project License)
-
項(xiàng)目團(tuán)隊(duì)信息(Project Team)
-
源碼庫(kù)信息(Source Repository)
根據(jù)筆者測(cè)試,以上信息均是在pom.xml進(jìn)行設(shè)置的。
-
持續(xù)集成信息根據(jù)以下配置信息生成:
<ciManagement>
<system/>
<url/>
<notifiers>
<notifier>
<type/>
<sendOnError/>
<sendOnFailure/>
<sendOnSuccess/>
<sendOnWarning/>
<address/>
<configuration/>
</notifier>
</notifiers>
</ciManagement>
-
依賴性信息根據(jù)以下配置信息有關(guān)
<dependencies> <dependency> <groupId/> <artifactId/> <version/> <type/> <classifier/> <scope/> <systemPath/> <exclusions> <exclusion> <artifactId/> <groupId/> </exclusion> </exclusions> <optional/> </dependency> </dependencies> |
-
發(fā)布追蹤信息
<issueManagement> <system/> <url/> </issueManagement> |
-
郵件列表信息
<mailingLists> <mailingList> <name/> <subscribe/> <unsubscribe/> <post/> <archive/> <otherArchives/> </mailingList> </mailingLists> |
筆者在pom.xml中設(shè)置以上信息后,運(yùn)行mvn site總會(huì)報(bào)錯(cuò)。如果哪位了解到報(bào)錯(cuò)原因請(qǐng)告訴我,謝謝。zhangxl@sintal.cn
-
工程協(xié)議信息
<licenses> <license> <name/> <url/> <distribution/> <comments/> </license> </licenses> |
-
項(xiàng)目團(tuán)隊(duì)信息
<organization> <name/> <url/> </organization> |
<developers> <developer> <id/> <name/> <email/> <url/> <organization/> <organizationUrl/> <roles/> <timezone/> <properties/> </developer> </developers>
|
<contributors> <contributor> <name/> <email/> <url/> <organization/> <organizationUrl/> <roles/> <timezone/> <properties/> </contributor> </contributors> |
-
源碼庫(kù)信息
<scm> <connection/> <developerConnection/> <tag/> <url/> </scm> |
默認(rèn)情況下這些文檔將生成在$basedir/src/site目錄下。
需要得到其他的報(bào)告,則需要配置其他的報(bào)告插件。
要想了解更多的信息,請(qǐng)參考以下網(wǎng)頁(yè):
http://cvs.peopleware.be/training/maven/maven2/morePlugins.html
依賴管理
這里我們通過使用外部依賴(external dependencies)來大家對(duì)maven的依賴管理有一個(gè)簡(jiǎn)單而具體的了解。
當(dāng)我們?cè)谧鲆粋€(gè)工程的時(shí)候,不可能一切都是從空白開始,對(duì)于我們做Web應(yīng)用的來說,使用框架已經(jīng)司空見慣,而這種對(duì)框架的引入使用對(duì)于Maven來說,就是工程的依賴。而我們的工程要進(jìn)行測(cè)試,則不能少了對(duì)Junit框架的依賴。
依賴管理是maven的一個(gè)主要特征,這個(gè)是對(duì)于用戶來說,是Maven令人振奮的一個(gè)最著名的特征。對(duì)于一個(gè)單一的工程來說,依賴管理沒有什么困難的,但是當(dāng)你開始處理多個(gè)模塊的工程或由10多個(gè)甚至上百個(gè)模塊組成的應(yīng)用程序時(shí), Maven能幫助你輕松穩(wěn)定的控制這些大量的依賴。
在pom.xml中dependencies部分列出了所有外部依賴,詳細(xì)描述了在編譯時(shí),測(cè)試時(shí),運(yùn)行時(shí)是否需要這個(gè)依賴。現(xiàn)在,假定我們的工程只有對(duì)Junit的依賴。它的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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
從以上pom.xml文件可以看出,定義一個(gè)外部依賴(external dependencies)至少需要4個(gè)元素:groupId, artifactId, version, and scope。對(duì)于groupId, artifactId, version的意思,和前面我們?cè)趧?chuàng)建工程時(shí)提到的這幾個(gè)元素的意義相同,這里就不再重復(fù)介紹,scope元素指出你的工程如何使用依賴,并且它的值有compile,test和runtime等等。想要了解更多的依賴說明的信息,請(qǐng)看
http://maven.apache.org/maven-model/maven.html
要想了解完整的依賴機(jī)制,請(qǐng)看
http://maven.apache.org/guides/introduction/introduction-to-dependency-management.html
有了這些依賴信息,Maven將能在工程構(gòu)建時(shí)引用依賴。
引用的過程是:
首先,在本地倉(cāng)庫(kù)(默認(rèn)的本地倉(cāng)庫(kù)地址為:~/.m2/repository)中查找此依賴是否存在。
再次,如果在本地倉(cāng)庫(kù)中未發(fā)現(xiàn),則在遠(yuǎn)程倉(cāng)庫(kù)中下載此依賴,并下載到本地倉(cāng)庫(kù)中。
最后,通過以上兩個(gè)步驟就能找到依賴。如果遠(yuǎn)程倉(cāng)庫(kù)無法訪問,則可以設(shè)置其他遠(yuǎn)程倉(cāng)庫(kù)。具體請(qǐng)看
http://maven.apache.org/guides/introduction/introduction-to-repositories.html
一個(gè)簡(jiǎn)單的例子。比如我們要添加一個(gè)log4j到我們的工程中。
首先.需要了解log4j的groupId, artifactId, and version信息。可在google上搜索“site:www.ibiblio.org maven2 log4j”。這樣在搜索結(jié)果里可以找到/maven2/log4j/log4j (or /pub/packages/maven2/log4j/log4j)這樣的目錄,在這個(gè)目錄中有一個(gè)文件叫做maven-metadata.xml。這個(gè)文件內(nèi)容如下所示:
-
<metadata>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.1.3</version>
<versioning>
<versions>
<version>1.1.3</version>
<version>1.2.4</version>
<version>1.2.5</version>
<version>1.2.6</version>
<version>1.2.7</version>
<version>1.2.8</version>
<version>1.2.11</version>
<version>1.2.9</version>
<version>1.2.12</version>
</versions>
</versioning>
</metadata>
這樣我們能找到groupId為log4j,artifactId為log4j,version當(dāng)然要用最新的,選擇1.2.12。scope我們?cè)O(shè)置為compile。
這樣我們使用mvn compile 編譯工程時(shí),會(huì)看到mvn下載了log4j到我們的本地倉(cāng)庫(kù)。
配置管理
Maven的配置管理是作為一個(gè)單獨(dú)的Maven子項(xiàng)目在做。叫做SCM。他是這樣介紹的:
MavenSCM支持Maven 2.x插件(例如,maven-release-plugin)和其他工具(例如,Continuum,這個(gè)是一個(gè)和maven 2.x結(jié)合很好的一個(gè)持續(xù)集成工具。),Maven SCM提供給他們一個(gè)公共的API去做配置管理的各種操作。當(dāng)然了要執(zhí)行配置管理操作,當(dāng)然少不了配置滾里工具了。Maven SCM給出了一個(gè)列表,說明Maven SCM現(xiàn)在所支持的配置管理工具。
完全支持的配置管理工具 |
CVS Subversion Perforce StarTeam |
部分支持的配置管理工具 |
ClearCase File system Visual Source Safe |
不支持的配置管理工具 |
Accurev Aegis Arch BitKeeper ClearCase Multisite CM Synergy Code Co-op Darcs Monotone OpenCM PureCM Serena PVCS / Dimension Starteam Enterprise Svk Vesta |
當(dāng)你選中了上面的一個(gè)配置管理工具,你就可以利用Maven 2.x的插件或者集成管理工具進(jìn)行配置管理了。
-
持續(xù)集成工具continuum
continuum是Maven的一個(gè)子項(xiàng)目。他是一個(gè)構(gòu)建基于java的工程的持續(xù)集成服務(wù)器。他支持以下多種工程類型:
-
Maven 1
-
Maven 2
-
Ant
-
Shell scripts
continuum有以下特征
-
緊密整合Maven 2.x
-
緊密整合Maven SCM
-
Subversion
-
CVS
-
Starteam
-
Clearcase
-
Perforce
-
-
更易用的基于網(wǎng)絡(luò)的設(shè)置和界面
-
基于Quartz(Quartz-based)的時(shí)間計(jì)劃表設(shè)置
-
添加新項(xiàng)目十分方便
-
郵件通知
-
其他IM通知
-
IRC
-
Jabber
-
MSN
-
-
責(zé)備機(jī)制(Blame Mechanism)
-
下載:
在以下連接處下載此軟件
http://maven.apache.org/continuum/download.html |
安裝:
Windows 2000/XP
解壓縮continuum-1.0.2-bin.zip到你希望安裝Continuum 1.0.2的所在目錄。這里假定你安裝在C:\Program Files\Apache Software Foundation\continuum-1.0下。
運(yùn)行:
-
bin/linux/run.sh 如果是UNIX平臺(tái)
-
bin/solaris/run.sh 如果是Solaris平臺(tái)
-
bin/win32/run.bat 如果是Windows平臺(tái)
-
bin/macosx/run.sh 如果是MacOS X平臺(tái).
-
bin/plexus.sh 如果是其他平臺(tái)
當(dāng)服務(wù)器啟動(dòng)成功后,打開瀏覽器訪問:
http://localhost:8080/continuum/ |
注意:由于continuum判斷一個(gè)工程是否構(gòu)建成功,是使用一個(gè)命令行返回值。而windows平臺(tái)的用戶,這個(gè)返回值有問題。因此需要修改以下maven 2的bin/mvn.bat文件。這里可以直接從以下地址下載修改后的文件替換掉即可。
http://maven.apache.org/continuum/scripts/mvn.bat |
-
添加一個(gè)項(xiàng)目到continuum
要添加一個(gè)maven 2的項(xiàng)目到continuum,需要寫入一個(gè)pom url或者導(dǎo)入一個(gè)pom.xml,當(dāng)然導(dǎo)入的這個(gè)pom.xml文件中包含了continuum需要的各種信息。
我們來看看導(dǎo)入的pom.xml文件中具體需要包含哪些項(xiàng):
-
配置管理信息(The SCM information)
<scm> <connection/> <developerConnection/> <tag/> <url/> </scm> |
-
開發(fā)者信息(The developers)
<ciManagement> <system>continuum</system> <notifiers> <notifier> ... </notifier> </notifiers> </ciManagement> |
-
集成后所有的通知人信息(The notifiers)
<notifier> <type>mail</type> <configuration> <address>dev@maven.apache.org</address> |
posted on 2009-07-24 09:27 so.java 閱讀(1166) 評(píng)論(0) 編輯 收藏 所屬分類: 隨想隨記