初一七月

你必须承认,我们生存的这个世界取决于自身的能力而非别人的保护(AW)
随笔 - 23, 文章 - 0, 评论 - 11, 引用 - 0
数据加载中……

Maven安装及测试

首先从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





posted on 2011-01-13 17:55 初一七月 阅读(6517) 评论(0)  编辑  收藏 所属分类: Maven


只有注册用户登录后才能发表评论。


网站导航: