Maven安裝及測(cè)試
首先從http://maven.apache.org/download.html下載二進(jìn)制安裝包,最新的版本是3.0.2。
windows下安裝:
1.將二進(jìn)制包apache-maven-3.0.2-bin.zip解壓至任意目錄,比如C:\apache-maven-3.0.2
2.設(shè)置環(huán)境變量,M2_HOME=C:\apache-maven-3.0.2,并且在PATH變量里添加%M2_HOME%\bin
3.測(cè)試配置是否生效,控制臺(tái)里輸入mvn -v或mvn -version,顯示如下信息,表示安裝已經(jīng)成功。
Maven的插件是在第一次加載時(shí)從倉(cāng)庫(kù)下載的,然后在本地保存一個(gè)副本,也就是說(shuō)第一次需要聯(lián)網(wǎng)到倉(cāng)庫(kù)去下載,新安裝的Maven只包含內(nèi)核,還不包含其他插件,我們可以使用describe目標(biāo)去試著獲取help插件的信息
因?yàn)槭堑谝淮渭虞d,所以會(huì)看到很多下載信息,在插件下載完成之后,最后才打印出help插件的具體信息
上面的輸出為help插件的Maven坐標(biāo),我們也可以看到新版本的Maven的9個(gè)目標(biāo),每個(gè)目標(biāo)都做了說(shuō)明,同時(shí)還包括了該插件的一個(gè)簡(jiǎn)要介紹、前綴等,如果你想要 Help 插件輸出完整的帶有參數(shù)的目標(biāo)列表,只要運(yùn)行帶有參數(shù)full的help:describe目標(biāo)就可以了
此時(shí)會(huì)輸出非常詳細(xì)的插件信息
該選項(xiàng)能讓你查看插件所有的目標(biāo)及相關(guān)參數(shù)。但是有時(shí)候這些信息顯得太多了。這時(shí)候你可以獲取單個(gè)目標(biāo)的信息,設(shè)置mojo參數(shù)和plugin參數(shù)。下面的命令列出了Compiler插件的compile目標(biāo)的所有信息
在Maven里面,一個(gè)插件目標(biāo)也被認(rèn)為是一個(gè)Mojo。比如上面我們看到help插件有system目標(biāo),所以我們可以這樣來(lái)查看help:system下的output信息
windows下安裝:
1.將二進(jìn)制包apache-maven-3.0.2-bin.zip解壓至任意目錄,比如C:\apache-maven-3.0.2
2.設(shè)置環(huán)境變量,M2_HOME=C:\apache-maven-3.0.2,并且在PATH變量里添加%M2_HOME%\bin
3.測(cè)試配置是否生效,控制臺(tái)里輸入mvn -v或mvn -version,顯示如下信息,表示安裝已經(jīng)成功。
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"
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的插件是在第一次加載時(shí)從倉(cāng)庫(kù)下載的,然后在本地保存一個(gè)副本,也就是說(shuō)第一次需要聯(lián)網(wǎng)到倉(cāng)庫(kù)去下載,新安裝的Maven只包含內(nèi)核,還不包含其他插件,我們可以使用describe目標(biāo)去試著獲取help插件的信息
mvn help:describe -Dplugin=help
因?yàn)槭堑谝淮渭虞d,所以會(huì)看到很多下載信息,在插件下載完成之后,最后才打印出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] ------------------------------------------------------------------------

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 [

[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坐標(biāo),我們也可以看到新版本的Maven的9個(gè)目標(biāo),每個(gè)目標(biāo)都做了說(shuō)明,同時(shí)還包括了該插件的一個(gè)簡(jiǎn)要介紹、前綴等,如果你想要 Help 插件輸出完整的帶有參數(shù)的目標(biāo)列表,只要運(yùn)行帶有參數(shù)full的help:describe目標(biāo)就可以了
mvn help:describe -Dplugin=help -Dfull
此時(shí)會(huì)輸出非常詳細(xì)的插件信息
[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] ------------------------------------------------------------------------

[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] ------------------------------------------------------------------------
該選項(xiàng)能讓你查看插件所有的目標(biāo)及相關(guān)參數(shù)。但是有時(shí)候這些信息顯得太多了。這時(shí)候你可以獲取單個(gè)目標(biāo)的信息,設(shè)置mojo參數(shù)和plugin參數(shù)。下面的命令列出了Compiler插件的compile目標(biāo)的所有信息
mvn help:describe -Dplugin=compiler -Dmojo=compile -Dfull
在Maven里面,一個(gè)插件目標(biāo)也被認(rèn)為是一個(gè)Mojo。比如上面我們看到help插件有system目標(biāo),所以我們可以這樣來(lái)查看help:system下的output信息
mvn help:system -Dplugin=help -Dmojo=output -Dfull
posted on 2011-01-13 17:55 初一七月 閱讀(6535) 評(píng)論(0) 編輯 收藏 所屬分類: Maven