File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes How to use the Ant Property file setting? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How to use the Ant Property file setting?" Watch "How to use the Ant Property file setting?" New topic

How to use the Ant Property file setting?

Roy Huang
Ranch Hand

Joined: Nov 21, 2001
Posts: 104
In the java ant samples, I have found some like
<property file="${env.ANT_HOME}/" />.
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.

SCJP 1.4/SCBCD/SCWCD<br />MCSE<br />IBM professional XML Developer<br />SAP certified Development Consultant (NetWeaver portal and Web JavaApplication)
Lewin Chan
Ranch Hand

Joined: Oct 10, 2001
Posts: 214
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.

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}"

I have no java certifications. This makes me a bad programmer. Ignore my post.
I agree. Here's the link:
subject: How to use the Ant Property file setting?
jQuery in Action, 3rd edition