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 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 OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP 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
author & internet detective

Joined: May 26, 2003
Posts: 31424

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.

[OCA 8 book] [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
Don't get me started about those stupid light bulbs.
subject: How to use If action in Ant