Calling ant target in known xml file from within an Ant Task

六月ゝ 毕业季﹏ 提交于 2020-02-04 04:04:47

问题


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");
}

回答1:


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();


来源:https://stackoverflow.com/questions/3655111/calling-ant-target-in-known-xml-file-from-within-an-ant-task

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!