Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

replace a content of a file based on build.properties

 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic