Take the 2-minute tour ×

I have made build.properties file in ant in which I have defined some variables as shown below

webinf.dir = WEB-INF

src.dir = ${webinf.dir}/src

Now these variable are accessed in ant build.xml file and its working fine. But I want to access these variables in my python file also. And I want value of src.dir to come as WEB-INF/src not as ${webinf.dir}/src

Please help how can I do this.


share|improve this question
add comment

1 Answer

I believe you can use a single properties file (e.g. build.py) that's read by Ant and Python. For example:


<project default="build">
    <property file="build.py"/>
    <target name="build">
        <echo message="${src.webinf}"/>



import ConfigParser
config = ConfigParser.ConfigParser()
print config.get("properties", "src.webinf")


src.webinf = WEB-INF

Example usage

$ ant
Buildfile: /Applications/MAMP/htdocs/clicks/test/build.xml

     [echo] WEB-INF

Total time: 0 seconds

$ python script.py 
share|improve this answer
Actually on second thought, using a shared properties files limits the key-value pairs you can have as properties, so you may want to investigate some third party Python libraries that can read Java properties files –  Minh Nguyen Jul 11 '13 at 5:45
Hi but my problem is src.dir = ${webinf.dir}/src I can't define variable as defined above. and while retrieving value of src.dir I want it to come full path. –  sanchit Jul 11 '13 at 5:55
I edited the Python script to use a ConfigParser. Does that work for you? –  Minh Nguyen Jul 11 '13 at 6:20
Ya I tried it but its not usefull as I am not getting the full path of src.dir It returns ${webinf.dir}/src but I want output as WEB-INF/src –  sanchit Jul 11 '13 at 6:52
The problem is that src.dir is created by Ant at runtime. Python cannot access that variable since it only has access to the initial properties file. Can't you just refactor your variables to put as much as possible into the properties file so that it can be shared with the Python script? –  Minh Nguyen Jul 11 '13 at 7:05
add comment

Your Answer


