tags:

views:

37

answers:

1

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");
}
+3  A: 

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