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

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

问题描述

我在写一个Ant任务:

 公共类MyTask扩展任务{    公共无效的execute(){
        ....
    }
}

现在我想知道是否有可能对我来说,调用在另一个著名的XML文件存在从上面的execute()方法中的一个目标是什么?

是这样的:

 公共无效的execute(){
    AntCaller.call(anotherBuildFile.xml,someTarget);
}


解决方案

您是在正确的轨道上。如果从XML想所有的另一个任务,你可以使用<蚂蚁> (因为它是另一个文件)可以从Java调用任务,只有当你有.class文件吧。幸运的是,你有Ant任务本身的.class文件,所以你可以使用同样的技术,你会在构建XML:

 蚂蚁帮手=新的Ant();
helper.setTarget(someTarget);
helper.setAntFile(anotherBuildFile.xml);
helper.execute();

I'm writing an Ant Task:

public class MyTask extends Task {

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

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?

Something like:

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

解决方案

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天全站免登陆