用法

跑步

maven-antrun-plugin 只有一个目标,运行

这允许 Maven 2 运行 Ant 任务。为此,必须有一个现有的项目并且 maven-antrun-plugin 必须配置其<tasks>标签(尽管它仍然会在没有<tasks>标签的情况下执行,但它不会做任何事情)。下面是maven-antrun-pluginpom.xml的模板。

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase> <!-- a lifecycle phase --> </phase>
            <configuration>
              <tasks>

                <!--
                  Place any Ant task here. You can add anything
                  you can add between <target> and </target> in a
                  build.xml.
                -->

              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

此外,您可以通过复制<execution/>部分并指定新阶段来将脚本添加到每个生命周期阶段。

最终,您可以在<tasks/>标记中指定一些 Ant <target/>属性。只有Ant <target/>中的depends属性没有被包装。

[...]
<configuration>
  <tasks name="The name of the tasks"
    if="The name of the property that must be set in order for this task"
    unless="The name of the property that must NOT be set in order for this task"
    description="A short description of this target's function">

    <!--
      Place any Ant task here. You can add anything
      you can add between <target> and </target> in a
      build.xml.
    -->

  </tasks>
<configuration>
[...]

下面你可以看到如何表明 Ant 已经生成了更多需要包含在编译阶段的 java 源代码。请注意,编译阶段遵循生命周期中的generate-sources阶段。

<project>
  [...]
  <build>
    <plugins>
      [...]
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <configuration>
              <tasks>

                <!--
                  Place any Ant task here. You can add anything
                  you can add between <target> and </target> in a
                  build.xml.
                -->

              </tasks>
              <sourceRoot>
                ${project.build.directory}/generated-sources/main/java
              </sourceRoot>
              <testSourceRoot>
                ${project.build.directory}/generated-sources/test/java
              </testSourceRoot>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

当然,您可以放置​​您喜欢的任何文件夹。上面示例中的文件夹很方便,因为它们在您清理时会被删除,因为它们位于构建目录中(默认情况下,“目标”)。

<sourceRoot/>将单个文件夹添加到使用程序源代码(compile)编译的文件夹列表中。

<testSourceRoot/>将单个文件夹添加到使用测试源代码 ( test-compile ) 编译的文件夹列表中。

Ant 表达式到 Maven 表达式的映射

一些 Ant 表达式在 Maven 中有它们各自的对应项。因此,可以简单地调用相应的 Maven 表达式,而不是使用 maven-antrun-plugin 来避免不必要的开销。

蚂蚁表情 Maven 表达式
内置任务
蚂蚁 maven-antrun-插件
蚂蚁呼叫 maven-antrun-插件
可用的 简介
B解压缩2 maven-程序集插件
BZip2 maven-程序集插件
修改 maven-程序集插件
健康)状况 简介
复制 Maven 资源插件
依赖集 maven 依赖插件
耳朵 maven-ear-插件
筛选 maven-resources-plugin
注意:过滤器使用 @...@ 标记,而 maven-resources-plugin 使用 ${...} 标记
修复CRLF Maven 资源插件
密钥 maven-jar-插件
G解压缩 maven-程序集插件
压缩包 maven-程序集插件
maven-jar-插件
Javac maven 编译器插件
Javadoc/Javadoc2 maven-javadoc-插件
加载属性 Maven 资源插件
显现 maven-jar-插件
财产 Maven 资源插件
代替 maven-resources-plugin
注意:Replace 可以指定其令牌,而 maven-resources-plugin 使用 ${...} 令牌
柏油 maven-程序集插件
解开 maven-程序集插件
解压 maven-程序集插件
温华 maven-程序集插件
解压 maven-程序集插件
战争 Maven 战争插件
压缩 maven-程序集插件
可选任务
蚂蚁 maven-antlr-插件
依靠 maven 依赖插件
EJB 任务 maven-ejb-插件
FTP maven-deploy-plugin
注意:maven-deploy-plugin 只能部署到 FTP
JavaCC maven 编译器插件
JJDoc maven 编译器插件
JJ树 maven 编译器插件
JUnit maven-surefire-插件
JUnitReport maven-surefire-report-plugin
服务器部署 Maven 部署插件
集代理 Maven 部署插件
翻译 maven-resources-plugin
注意:Translate 可以指定自己的标记,并且可以有不同的编码方案来读写文件。然而,maven-resources-plugin 仅使用 ${...} 注释并且只有一种用于读写的编码方案