如何在Ant中向目标的末尾添加命令?

时间:2014-03-05 04:37:01

标签: java ant

我不太了解蚂蚁。我在网上找到了很多代码,我想将它追加到已经存在的目标的末尾,我无法直接编辑。我怎么能这样做?

Java示例(为清晰起见):

public methodName() {
  super.methodName();
  a++;
}

1 个答案:

答案 0 :(得分:2)

这是一个小样本Ant构建文件。默认目标是post.process。这可能是您在现有流程运行后要执行的处理。我还添加了一个名为'around'的目标。这将调用before target,然后调用现有目标,最后调用process.process target。

<project name="Test Dependency" basedir="." default="post.process">

    <target name="existing.target" description="Existing target">
        <echo>Existing target that you cannot change</echo>
    </target>

    <target name="post.process"  description="new post processing " depends="existing.target">
        <echo>New target that runs after existing target</echo>
    </target>

    <target name="around"  description="processing around existing target" depends="before.process,existing.target,post.process"/>

    <target name="before.process" description="run before existing target">
       <echo>runs before existing target when target around called </echo>
    </target>

</project>.

以下是运行此文件的结果。首先输入ant或ant post.process。因为项目标记将post.process定义为默认目标,所以如果没有目标传递,则使用它。

你可以在没有引号的情况下跑'蚂蚁。以下是结果。

Mikes-MacBook-Pro:J7 mike$ ant
Buildfile: build.xml

existing.target:
     [echo] Existing target that you cannot change

post.process:
     [echo] New target that runs after existing target

BUILD SUCCESSFUL
Total time: 0 seconds
Mikes-MacBook-Pro:J7 mike$ ant around
Buildfile: build.xml

before.process:
     [echo] runs before existing target when target around called 

existing.target:
     [echo] Existing target that you cannot change

post.process:
     [echo] New target that runs after existing target

around: