aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes replace a content of a file based on build.properties 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 "replace a content of a file based on build.properties" Watch "replace a content of a file based on build.properties" New topic
Author

replace a content of a file based on build.properties

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
I am working on build.xml file. I have completed and I have got the output as well..

Now my concern is how do I replace a content in an application.property file based on a value from my build.properties.

In my build.xml file I have to replace the value of deploy.mode in a property file as dev, test or prod based on the build.property file..

Can anyone advise..
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

The rule for Ant is whoever defines a property first wins. That's the opposite of most environments, where the last definition is the one that's taken.

An easy way to do what you want is to take advantage of the fact that Ant is a Java app and Java apps can be passed properties via the command line:

ant -Ddeploy.mode=test target-name


Customer surveys are for companies who didn't pay proper attention to begin with.
rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
I understand your point from the command line...Say If I wanted to replace few other values in my property file other than this deploy.mode.. How do i do the same?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5837
    
    7

One way is to add the extra property values to the command line.

Another way is to set up your build.xml to load another properties file before your build.properties file. The user could then override property values using that file, and thus save a lot of typing on the command line.


JBoss In Action
 
Consider Paul's rocket mass heater.
 
subject: replace a content of a file based on build.properties