首先從http://maven.apache.org/download.html下載二進制安裝包,最新的版本是3.0.2。
windows下安裝:
1.將二進制包apache-maven-3.0.2-bin.zip解壓至任意目錄,比如C:\apache-maven-3.0.2
2.設置環境變量,M2_HOME=C:\apache-maven-3.0.2,并且在PATH變量里添加%M2_HOME%\bin
3.測試配置是否生效,控制臺里輸入mvn -v或mvn -version,顯示如下信息,表示安裝已經成功。
Apache Maven 3.0.2 (r1056850; 2011-01-09 08:58:10+0800)
Java version: 1.6.0_10-rc2, vendor: Sun Microsystems Inc.
Java home: C:\Java\jdk1.6.0_10\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
Maven的插件是在第一次加載時從倉庫下載的,然后在本地保存一個副本,也就是說第一次需要聯網到倉庫去下載,新安裝的Maven只包含內核,還不包含其他插件,我們可以使用describe目標去試著獲取help插件的信息
mvn help:describe -Dplugin=help
因為是第一次加載,所以會看到很多下載信息,在插件下載完成之后,最后才打印出help插件的具體信息
[INFO] Scanning for projects
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom (5 KB at 2.3 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugins/18/maven-plugins-18.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugins/18/maven-plugins-18.pom (13 KB at 18.5 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/16/maven-parent-16.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/16/maven-parent-16.pom (23 KB at 33.0 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/apache/7/apache-7.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/apache/7/apache-7.pom (15 KB at 20.5 KB/sec)

[INFO] org.apache.maven.plugins:maven-help-plugin:2.1.1
Name: Maven Help Plugin
Description: The Maven Help plugin provides goals aimed at helping to make
sense out of the build environment. It includes the ability to view the
effective POM and settings files, after inheritance and active profiles have
been applied, as well as a describe a particular plugin goal to give usage
information.
Group Id: org.apache.maven.plugins
Artifact Id: maven-help-plugin
Version: 2.1.1
Goal Prefix: help
This plugin has 9 goals:
help:active-profiles
Description: Displays a list of the profiles which are currently active for
this build.
help:all-profiles
Description: Displays a list of available profiles under the current
project.
Note: it will list all profiles for a project. If a profile comes up with a
status inactive then there might be a need to set profile activation
switches/property.
help:describe
Description: Displays a list of the attributes for a Maven Plugin and/or
goals (aka Mojo - Maven plain Old Java Object).
help:effective-pom
Description: Displays the effective POM as an XML for this build, with the
active profiles factored in.
help:effective-settings
Description: Displays the calculated settings as XML for this project,
given any profile enhancement and the inheritance of the global settings
into the user-level settings.
help:evaluate
Description: Evaluates Maven expressions given by the user in an
interactive mode.
help:expressions
Description: Displays the supported Plugin expressions used by Maven.
help:help
Description: Display help information on maven-help-plugin.
Call
mvn help:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
help:system
Description: Displays a list of the platform details like system properties
and environment variables.
For more information, run 'mvn help:describe [
] -Ddetail'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:29.749s
[INFO] Finished at: Thu Jan 13 17:01:15 CST 2011
[INFO] Final Memory: 3M/7M
[INFO] ------------------------------------------------------------------------
上面的輸出為help插件的Maven坐標,我們也可以看到新版本的Maven的9個目標,每個目標都做了說明,同時還包括了該插件的一個簡要介紹、前綴等,如果你想要 Help 插件輸出完整的帶有參數的目標列表,只要運行帶有參數full的help:describe目標就可以了
mvn help:describe -Dplugin=help -Dfull
此時會輸出非常詳細的插件信息
[INFO] Scanning for projects
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.1.1:describe (default-cli) @ standalone-pom ---
[INFO] org.apache.maven.plugins:maven-help-plugin:2.1.1
Name: Maven Help Plugin
Description: The Maven Help plugin provides goals aimed at helping to make
sense out of the build environment. It includes the ability to view the
effective POM and settings files, after inheritance and active profiles have
been applied, as well as a describe a particular plugin goal to give usage
information.
Group Id: org.apache.maven.plugins
Artifact Id: maven-help-plugin
Version: 2.1.1
Goal Prefix: help
This plugin has 9 goals:
help:active-profiles
Description: Displays a list of the profiles which are currently active for
this build.
Implementation: org.apache.maven.plugins.help.ActiveProfilesMojo
Language: java
Available parameters:
output
Expression: ${output}
Optional parameter to write the output of this help in a given file,
instead of writing to the console.
Note: Could be a relative path.
help:all-profiles
Description: Displays a list of available profiles under the current
project.
Note: it will list all profiles for a project. If a profile comes up with a
status inactive then there might be a need to set profile activation
switches/property.
Implementation: org.apache.maven.plugins.help.AllProfilesMojo
Language: java
Available parameters:
output
Expression: ${output}
Optional parameter to write the output of this help in a given file,
instead of writing to the console.
Note: Could be a relative path.
help:describe
Description: Displays a list of the attributes for a Maven Plugin and/or
goals (aka Mojo - Maven plain Old Java Object).
Implementation: org.apache.maven.plugins.help.DescribeMojo
Language: java
Available parameters:
artifactId
Expression: ${artifactId}
The Maven Plugin artifactId to describe.
Note: Should be used with groupId parameter.
cmd
Expression: ${cmd}
A Maven command like a single goal or a single phase following the Maven
command line:
mvn [options] [<goal(s)>] [<phase(s)>]
detail (Default: false)
Expression: ${detail}
This flag specifies that a detailed (verbose) list of goal (Mojo)
information should be given.
goal
Expression: ${goal}
The goal name of a Mojo to describe within the specified Maven Plugin. If
this parameter is specified, only the corresponding goal (Mojo) will be
described, rather than the whole Plugin.
groupId
Expression: ${groupId}
The Maven Plugin groupId to describe.
Note: Should be used with artifactId parameter.
medium (Default: true)
Expression: ${medium}
This flag specifies that a medium list of goal (Mojo) information should
be given.
minimal (Default: false)
Expression: ${minimal}
This flag specifies that a minimal list of goal (Mojo) information should
be given.
output
Expression: ${output}
Optional parameter to write the output of this help in a given file,
instead of writing to the console.
Note: Could be a relative path.
plugin
Expression: ${plugin}
The Maven Plugin to describe. This must be specified in one of three
ways:
1. plugin-prefix, i.e. 'help'
2. groupId:artifactId, i.e. 'org.apache.maven.plugins:maven-help-plugin'
3. groupId:artifactId:version, i.e.
'org.apache.maven.plugins:maven-help-plugin:2.0'
version
Expression: ${version}
The Maven Plugin version to describe.
Note: Should be used with groupId/artifactId parameters.
help:effective-pom
Description: Displays the effective POM as an XML for this build, with the
active profiles factored in.
Implementation: org.apache.maven.plugins.help.EffectivePomMojo
Language: java
Available parameters:
output
Expression: ${output}
Optional parameter to write the output of this help in a given file,
instead of writing to the console.
Note: Could be a relative path.
help:effective-settings
Description: Displays the calculated settings as XML for this project,
given any profile enhancement and the inheritance of the global settings
into the user-level settings.
Implementation: org.apache.maven.plugins.help.EffectiveSettingsMojo
Language: java
Available parameters:
output
Expression: ${output}
Optional parameter to write the output of this help in a given file,
instead of writing to the console.
Note: Could be a relative path.
showPasswords (Default: false)
Expression: ${showPasswords}
For security reasons, all passwords are hidden by default. Set this to
true to show all passwords.
help:evaluate
Description: Evaluates Maven expressions given by the user in an
interactive mode.
Implementation: org.apache.maven.plugins.help.EvaluateMojo
Language: java
Available parameters:
artifact
Expression: ${artifact}
An artifact for evaluating Maven expressions.
Note: Should respect the Maven format, i.e.
groupId:artifactId[:version][:classifier].
expression
Expression: ${expression}
An expression to evaluate instead of prompting. Note that this must not
include the surrounding ${
}.
help:expressions
Description: Displays the supported Plugin expressions used by Maven.
Implementation: org.apache.maven.plugins.help.ExpressionsMojo
Language: java
Available parameters:
output
Expression: ${output}
Optional parameter to write the output of this help in a given file,
instead of writing to the console.
Note: Could be a relative path.
help:help
Description: Display help information on maven-help-plugin.
Call
mvn help:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
Implementation: org.apache.maven.plugins.help.HelpMojo
Language: java
Available parameters:
detail (Default: false)
Expression: ${detail}
If true, display all settable properties for each goal.
goal
Expression: ${goal}
The name of the goal for which to show help. If unspecified, all goals
will be displayed.
indentSize (Default: 2)
Expression: ${indentSize}
The number of spaces per indentation level, should be positive.
lineLength (Default: 80)
Expression: ${lineLength}
The maximum length of a display line, should be positive.
help:system
Description: Displays a list of the platform details like system properties
and environment variables.
Implementation: org.apache.maven.plugins.help.SystemMojo
Language: java
Available parameters:
output
Expression: ${output}
Optional parameter to write the output of this help in a given file,
instead of writing to the console.
Note: Could be a relative path.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.313s
[INFO] Finished at: Thu Jan 13 17:38:55 CST 2011
[INFO] Final Memory: 3M/7M
[INFO] ------------------------------------------------------------------------
該選項能讓你查看插件所有的目標及相關參數。但是有時候這些信息顯得太多了。這時候你可以獲取單個目標的信息,設置mojo參數和plugin參數。下面的命令列出了Compiler插件的compile目標的所有信息
mvn help:describe -Dplugin=compiler -Dmojo=compile -Dfull
在Maven里面,一個插件目標也被認為是一個Mojo。比如上面我們看到help插件有system目標,所以我們可以這樣來查看help:system下的output信息
mvn help:system -Dplugin=help -Dmojo=output -Dfull