ePrivacy and GPDR Cookie Consent by Cookie Consent Enumerating Ant Targets Programatically - Develop In Java
Develop In Java
All things Java and development

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

Credits

Photo by Vlad Tchompalov on Unsplash