全部,
如果目录存在,有人可以帮助如何有条件地在路径元素中包含目录:所以如下所示
<path id="lib.path.ref">
<fileset dir="${lib.dir}" includes="*.jar"/>
<path location="${build.dir}" if="${build.dir.exist}" />
</path>
这目前不起作用,因为 path 元素不支持 if 属性。就我而言,如果只有 build.dir 存在,我想包含它。
谢谢
无需安装Ant-Contrib或类似的 Ant 扩展,您可以使用以下 XML 完成您想要的:
<project default="echo-lib-path">
<property name="lib.dir" value="lib"/>
<property name="build.dir" value="build"/>
<available file="${build.dir}" type="dir" property="build.dir.exists"/>
<target name="-set-path-with-build-dir" if="build.dir.exists">
<echo message="Executed -set-path-with-build-dir"/>
<path id="lib.path.ref">
<fileset dir="${lib.dir}" includes="*.jar"/>
<path location="${build.dir}" />
</path>
</target>
<target name="-set-path-without-build-dir" unless="build.dir.exists">
<echo message="Executed -set-path-without-build-dir"/>
<path id="lib.path.ref">
<fileset dir="${lib.dir}" includes="*.jar"/>
</path>
</target>
<target name="-init" depends="-set-path-with-build-dir, -set-path-without-build-dir"/>
<target name="echo-lib-path" depends="-init">
<property name="lib.path.property" refid="lib.path.ref"/>
<echo message="${lib.path.property}"/>
</target>
</project>
这里重要的部分是-init目标中发生的事情。它取决于-set-path-with-build-dir和-set-path-without-build-dir目标,但 Ant 仅根据是否build.dir.exists设置执行一个目标。
在此处阅读有关可用任务的更多信息:http: //ant.apache.org/manual/Tasks/available.html。