从 Ant 任务中调用已知 xml 文件中的 ant 目标 [英] Calling ant target in known xml file from within an Ant Task

查看:26
本文介绍了从 Ant 任务中调用已知 xml 文件中的 ant 目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Ant 任务:

I'm writing an Ant Task:

public class MyTask extends Task {

    public void execute() {
        ....
    }
}

现在我想知道是否可以从上述 execute() 方法中调用存在于另一个已知 xml 文件中的目标?

Now I'm wondering whether it is possible for me to call a target that exists in another known xml file from within the above execute() method?

类似于:

public void execute() {
    AntCaller.call("anotherBuildFile.xml", "someTarget");
}

推荐答案

您走对了.如果您想从 XML 调用所有其他任务,您可以使用 (因为它是另一个文件.)只有当您拥有 .class 文件时,您才能从 Java 调用任务.幸运的是,您确实拥有 Ant 任务本身的 .class 文件,因此您可以使用与构建 xml 中相同的技术:

You are on the right track. If you wanted to all another task from XML, you would use <ant> (since it is another file.) You can call a task from Java only if you have the .class file for it. Luckily, you do have the .class file for the Ant task itself so you can use the same technique as you would in a build xml:

Ant helper = new Ant();
helper.setTarget("someTarget");
helper.setAntFile("anotherBuildFile.xml");
helper.execute();

这篇关于从 Ant 任务中调用已知 xml 文件中的 ant 目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆