Meaningless Drivel is fun!*
The moose likes Ant, Maven and Other Build Tools and the fly likes How to use If action in Ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to use If action in Ant" Watch "How to use If action in Ant" New topic

How to use If action in Ant

Sachin Dare

Joined: May 04, 2004
Posts: 12
Hello World,
I want to use the replace action on some conditions, I am not able to do the conditioning part.
Kindly help me in this. I do not want to use Ant Contrib for this.
I want something like this -

<if environment-type="Dev">
<replace file="${dir.src}/log4j.xml" token="@@@" value="DEBUG"/>

<if environment-type="QA">
<replace file="${dir.src}/log4j.xml" token="@@@" value="INFO"/>

<if environment-type="Prod">
<replace file="${dir.src}/log4j.xml" token="@@@" value="WARN"/>

Thanks a lot in advance.
Sachin Dare.
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30076

It's a lot more code without Ant contrib. Here's the pattern. You use one target to set the conditional properties. Then you use another target for the replace. You need a separate target for each if statement you want. Then you need to tie them all together in order.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
I agree. Here's the link:
subject: How to use If action in Ant
Similar Threads
append a batch file
Case sensitive Issue when using Ant Replace task
JBuilder 9 with JDK1.5.0 beta
ant waits for user input
generated WSDL through wsgen and REPLACE_WITH_ACTUAL_URL