【发布时间】:2012-07-16 13:39:48
【问题描述】:
在我们的项目中,我们有一个 common.xml,它包含在我们所有的 ant 文件中。这个 common.xml 包含我们在项目中使用的所有常见任务。
最近我们想在我们的项目中使用 ant-contrib。所以我们在 common.xml
中包含了以下任务定义<project name="CommonTasks" basedir="." xmlns:ac="antlib:net.sf.antcontrib">
<taskdef uri="antlib:net.sf.antcontrib" resource="net/sf/antcontrib/antlib.xml>
<classpath>
<pathelement location="/usr/lib/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>
</project>
在我们的 build.xml 之一中,我们有以下代码
<project name="Build" basedir=".">
<import file="common.xml" />
<ac:if>
<ac:not>
<isset property="android.available" />
</ac:not>
<ac:then>
<echo message="android is not available" />
</ac:then>
</ac:if>
</project>
现在我们假设命名空间是在 common.xml 中定义的,同样的也会被导入到我们的 build.xml 中。但这并没有发生。相反,我需要为我的 build.xml 包含 xmlns:ac="antlib:net.sf.antcontrib" 每个。即我的 build.xml 应该如下所示
<project name="Build" basedir="." xmlns:ac="antlib:net.sf.antcontrib">
<import file="common.xml" />
<ac:if>
<ac:not>
<isset property="android.available" />
</ac:not>
<ac:then>
<echo message="android is not available" />
</ac:then>
</ac:if>
</project>
有没有办法在我们所有的 build.xml 中执行此命名空间导入,而不是在所有 build.xml 中定义相同的命名空间定义
【问题讨论】:
-
没有。 XML 事物中的 XML 命名空间声明。例如,如果您导入了两个文件,每个文件都提供“ac”前缀。 XML 解析器应该使用哪一个?这就是命名空间声明必须出现在 XML 文件顶部的原因。
标签: ant build build-automation