Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/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 如何在Ant'中使用通配符;s可用命令_Java_Ant - Fatal编程技术网

Java 如何在Ant'中使用通配符;s可用命令

Java 如何在Ant'中使用通配符;s可用命令,java,ant,Java,Ant,我正在使用一个Ant构建脚本来整理我的基于Eclipse的应用程序以供发布 构建的一个步骤是检查构建文件夹中是否存在正确的库。我目前使用Ant命令进行此操作。不幸的是,每次切换到新的Eclipse构建时,我都必须修改脚本(因为版本号会更新) 我不需要检查版本号,我只需要检查文件是否存在 那么,我如何检查: org.eclipse.rcp_3.5.0.* 而不是: org.eclipse.rcp_3.5.0.v20090519-9SA0FwxFv6x089WEf-TWh11 使用蚂蚁 干杯,

我正在使用一个Ant构建脚本来整理我的基于Eclipse的应用程序以供发布

构建的一个步骤是检查构建文件夹中是否存在正确的库。我目前使用Ant命令进行此操作。不幸的是,每次切换到新的Eclipse构建时,我都必须修改脚本(因为版本号会更新)

我不需要检查版本号,我只需要检查文件是否存在

那么,我如何检查:

org.eclipse.rcp_3.5.0.*
而不是:

org.eclipse.rcp_3.5.0.v20090519-9SA0FwxFv6x089WEf-TWh11
使用蚂蚁

干杯, 伊恩

你的意思是(基于,after):


在大多数情况下,pathconvert任务可能是首选方法。但是,当目录树非常大并且使用echoproperties任务时,会产生一个小问题。对于非常大的目录树,pathconvert生成的字符串可能非常大。然后echoproperties喷洒巨大的字符串,使输出更加难以处理。我在Linux上使用macrodef,如果目录中有文件,它会将属性设置为“1”:

<macrodef name="chkDirContents" >
    <attribute name="propertyName" />
    <attribute name="dirPath" />
    <attribute name="propertyFile" />
    <sequential>
        <exec executable="sh" dir="." failonerror="false" >
            <arg value="-c" />
            <arg value='fyles=`ls -1 @{dirPath} | head -1` ; if [ "$fyles" != "" ] ; then echo @{propertyName}=1 > @{propertyFile} ; fi' />
        </exec>
    </sequential>
</macrodef>

<target name="test" >
    <tempfile destdir="." property="temp.file" deleteonexit="true" />
    <chkDirContents propertyName="files.exist" dirPath="./target_dir" propertyFile="${temp.file}" />
    <property file="${temp.file}" />

    <echoproperties/>
</target>
[echoproperties] files.exist=1
“测试”的作用是: 它生成一个临时文件名${temp.file},以后可以用作属性文件。 然后执行macrodef,它调用shell来检查dirPath目录的内容。如果dirPath中有任何文件或目录,则会在临时文件中为propertyName属性指定值1。然后它读取文件并设置文件中给定的属性。如果文件为空,则未定义任何属性


请注意,如果需要,可以将临时文件重新用于随后的宏定义调用。当然,另一方面,一旦设置了属性,它是不可变的。

一种稍微简短、更直接的条件处理方法:

<target name="checkEclipseRcp">
    <condition property="foundRcp">
        <resourcecount when="greater" count="0">
            <fileset file="/folder/folder/eclipse/org.eclipse.rcp_3.5.0.*"/>
        </resourcecount>
    </condition>
</target>

<target name="process" depends="checkEclipseRcp" if="foundRcp">
  <!-- do something -->
</target>


听起来很完美-我非常想试一试。如果我三年前问这个问题,我会节省很多时间。干杯,你真是太慷慨了,能介入并提供改进。如果我在4年前意识到这一改进就好了,当时我评论说我在3年前就意识到了基本解决方案。谁知道5年后我会有什么进步?
<target name="checkEclipseRcp">
    <condition property="foundRcp">
        <resourcecount when="greater" count="0">
            <fileset file="/folder/folder/eclipse/org.eclipse.rcp_3.5.0.*"/>
        </resourcecount>
    </condition>
</target>

<target name="process" depends="checkEclipseRcp" if="foundRcp">
  <!-- do something -->
</target>