Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use the Ant Property file setting?

 
Roy Huang
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the java ant samples, I have found some like
<property file="${env.ANT_HOME}/ant.properties" />.
My question is:
1. How to use the settings in the property files?
In java we can use Properties.load(Inputstream) and then use getProperty("key1") to get the value of key1. But How can I let my java code know it should load the property file from the Ant XML file setting? What should I use from the Ant API to bind with the ant xml file settings?
2. Does the ${env.ANT_HOME} also work for Windows NT platform? In my case, it doesn't work.
Thanks,
Roy
 
Lewin Chan
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roy,
1) Just use them, like

where build.dir etc are just all defined in the property file.

It doesn't necessarily help your java code at all, but it can externalise any variables that you want in your build script into a properties file.
If you are intending to run your java code within ant, then they may be passed as part of the default system properties, or they may not.

2)
a) if ANT_HOME hasn't been defined in your environment then you won't be able to use it...
b) If you want to use environment variables, then you may need to use the

Task before you can reference variables as "${my_prefix.ENV_VAR}"
L
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic