Enumerating Ant Targets Programatically

Login | Register

Enumerating Ant Targets Programatically

In my previous blog post, I provided some sample code showing how to execute ant targets programatically from Java. This code showed how to execute the default ant target.

Enumerating the targets is a similarly easy process. The code below shows how to iterate through all the ant targets within an ant build file.

Project p = new Project();  
// Setup Project p
Hashtable table = p.getTargets();  
Set set = table.keySet();  
Iterator iter = set.iterator();  
while (iter.hasNext()) {  
    System.out.println("Target:"+(String)iter.next());
}

About

At Develop In Java, we've been a part of the Java community for over 10 years. If there's anything you'd like us to cover, just ask !

Current versions

  • Java - 1.8
  • Java EE - 7
  • Spring - 4.x