Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 路径元素包含条件_Java_Eclipse_Ant - Fatal编程技术网

Java 路径元素包含条件

Java 路径元素包含条件,java,eclipse,ant,Java,Eclipse,Ant,全部, 如果目录存在,有人能帮助我们有条件地在path元素中包含目录吗 <path id="lib.path.ref"> <fileset dir="${lib.dir}" includes="*.jar"/> <path location="${build.dir}" if="${build.dir.exist}" /> </path> 这当前不起作用,因为path元素不支持if属性。在我的例子中,如果build.dir存

全部,

如果目录存在,有人能帮助我们有条件地在path元素中包含目录吗

<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扩展,您可以使用以下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>


.

刚刚为您找到了这个:可能会有帮助。非常感谢您抽出时间给出一个清晰简洁的工作解决方案。感谢这个社区。