• Post Reply Bookmark Topic Watch Topic
  • New Topic

set Property values programatically  RSS feed

 
An Sush
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a requirement as follows:
Have to run ant script using Java. I want to make this call very generic and thus using properties file to configure the properties/values i need to pass to the ant script. For each ant target, i have a propety file which inputs the variables for example the ant file is:



and this is the properties file for the target stopApp (in this case only one):


Now I am able to set the propeties like WAS_CELL, WAS_NODE etc programatically from java. I want to set the propety PWD as present in the stopApp.propeties programatically to the present working directory. Is it possible to do?

In short to simplify the problem is it possible to set property values in a property file programatically(in java)?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java provides the java.util.Properties class to make it easy to read, modify and write "properties" formatted text files.

Bill
 
Tim Holloway
Saloon Keeper
Posts: 18799
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create properties files in Java, but I don't think that will help here.

For a case where you have a list of servers you want to stop, here's one solution:

1. Create a properties file for each server, giving each one a useful name - something like server1.properties, server2.properties, etc.

2. Set up your Ant script to substitute in the server name and load the properties of interest. Like so:

<loadproperties>
<file file="${server}.properties"/>
</loadproperties>

3. Invoke Ant and pass in the server name:

ant -Dserver=server1

Notice no spaces in the "-D" option! If it needs spaces, use shell quoting or the command won't parse right.

4. If you want extra geek points, you can wrap it all in a shell script that plugs in the Ant command line options:

stopServer server1

or

serverControl server1 stop
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!