0

我在 ant 中创建了 build.properties 文件,其中定义了一些变量,如下所示

webinf.dir = WEB-INF

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

现在这些变量可以在 ant build.xml 文件中访问,并且工作正常。但我也想在我的 python 文件中访问这些变量。而且我希望src.dir的价值WEB-INF/src不像${webinf.dir}/src

我怎样才能做到这一点?

4

1 回答 1

0

我相信您可以使用 Ant 和 Python 读取的单个属性文件(例如 build.py)。例如:

构建.xml

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

脚本.py

#!/usr/bin/python

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

构建.py

[properties]
src.webinf = WEB-INF

示例用法

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

build:
     [echo] WEB-INF

BUILD SUCCESSFUL
Total time: 0 seconds

$ python script.py 
WEB-INF
于 2013-07-11T05:42:40.803 回答