Meaningless Drivel is fun!*
The moose likes Ant, Maven and Other Build Tools and the fly likes Creating for loops in ANT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Creating for loops in ANT" Watch "Creating for loops in ANT" New topic
Author

Creating for loops in ANT

Cindy Martin
Greenhorn

Joined: Jul 29, 2008
Posts: 10
Hi,

can we write a build file with a for loop that runs n times ?

For eg., i want to run a for loop for n no of time depends on the value of n. But i dont want to write in java and call in build file...i am just trying with ANT tasks itself todo this... if anyone gives me a hint, or know abt how to write, kindly help me...

Cindy
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Ant doesn't directly support this. It very deliberately doesn't have scripting-like constructs becasue it is not a scripting language. However, you can get the ant-contrib extensions which include this sort of stuff.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41108
    
  45
Or you could write your own AntTask that reads a property from the build file, and iterates accordingly. It's not that hard.


Ping & DNS - my free Android networking tools app
Cindy Martin
Greenhorn

Joined: Jul 29, 2008
Posts: 10
Thanks Paul and Ulf !! you have given me a hint...

Using ANT Contrib tasks , i just wrote the simple loop


This code results in, printing the values one by one. But the size is fized and i need to give all the inputs in the list attribute...Is there any way that i can specify the list = No of values (n) and iterate it by the loop ( i= i+1). I tried several possibilities, but i cud not get it. Can anyone help me ?

Cindy
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

Try this:



then run ant as:

ant -Dmy.list=1,2,3,4,5

Or you can set the my.list property in a properties file or in another location within the script.


JBoss In Action
 
 
subject: Creating for loops in ANT
 
Similar Threads
ANT: calling a target from another build file
Ant tool and build.xml
About ".classpath" file in the project
Ant v/s other build tools
Ant script for WAS 7