File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes ANT, targets and variable passing 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 "ANT, targets and variable passing" Watch "ANT, targets and variable passing" New topic

ANT, targets and variable passing

David Edds

Joined: Dec 06, 2004
Posts: 20

I have limited experience of ant, but am wondering if it is possible to pass arguments to a target so the target operates on the supplied values. Note that I am making a distincation using "environment variables". What I wish to do is pass a value to a target and then run the target operating on those values. I guess this is impossible, since I assume that this is not the way ant really works, but I wondered if anyone knew how to do this.

The reason I want to do this, is because I have the following scenario:

I have a series of tasks to perform in ant. They start off with general tasks, (e.g. cvsCheckout, amalgamate) and then go into a series of tasks for a particular file-set (e.g. compile, junit, coverage, javadoc). I need to repeat that set of tasks for different file sets. Once I have done that I do a couple more general tasks (e.g. clean-up, publish) and I'm done.

I can achieve the above by writing the following targets in my ant script:

But surely there is a way to do this without all of the repetition? The targets compileSet1 and compileSet2 are very similar, they just work on different filesets and different file locations.

Any help or advice is greatly appreciated,
madhu yadav

Joined: Apr 27, 2003
Posts: 3
You can use macros as an alternative to these targets.
As u said except the filesets these targets are similar,
u can pass these as parameters to the macro.
Please refer to the ant 1.6.2 manual for further reference.
David Edds

Joined: Dec 06, 2004
Posts: 20
Thanks Madhu,

That is the sort of thing I need. I have tried it out and it works well.

Thanks again,
I agree. Here's the link:
subject: ANT, targets and variable passing
It's not a secret anymore!