This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
Author

How to use If action in Ant

Sachin Dare
Greenhorn

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>

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

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

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

Joined: May 26, 2003
Posts: 30123
    
150

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
 
It is sorta covered in the JavaRanch Style Guide.
 
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