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
Ant 蚂蚁属性选择器问题_Ant_Properties_Foreach - Fatal编程技术网

Ant 蚂蚁属性选择器问题

Ant 蚂蚁属性选择器问题,ant,properties,foreach,Ant,Properties,Foreach,我正试图使用ant contrib任务从属性文件中提取一些值,但我不断得到下面的错误。我从搜索结果中尝试了很多不同的想法,但我仍然没有进一步的进展 xml:9: Property '${constituents}' is not defined. 我的生成文件是: <project name="hello" default="foo"> <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> <t

我正试图使用ant contrib任务从属性文件中提取一些值,但我不断得到下面的错误。我从搜索结果中尝试了很多不同的想法,但我仍然没有进一步的进展

xml:9: Property '${constituents}' is not defined.
我的生成文件是:

<project name="hello" default="foo">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<target name="foo">
    <property file="props.file"/>
    <propertyselector property="constituents" match="\bDIR1/workDir([^.]+)\b" select="\0" casesensitive="false"/>
    <foreach list="${constituents}" target="print.name" param="myparam"/>
</target>
<target name="print.name">
    <propertycopy property="key" from="${myparam}"/>
    <echo message="${key}"/>
</target>
我基本上是试图提取所有开始的测试:

DIR1/workDir/......
我希望有人能给我一个指示,告诉我哪里出了问题

谢谢

请参阅:

选择与给定正则表达式匹配的属性名,并在分隔列表中返回它们

所以你做错了-选择属性名,而不是值。当您的某些属性与名称共享一个模式时,应该使用它,请参见手册页面中的示例

做你想做的事的另一种(或典型的蚂蚁)方法:

constituents=ABC_Section,\
    DIR1/workDir/sec1/subSec1/File1,\
    DIR1/workDir/sec2/File2,\
    DIR1/workDir/sec3/File3,\
    DIR1/workDir/lib,\
    DIR1/OTHER
然后


@{myparam}
我没有在
匹配中测试正则表达式,您可能需要修复它

constituents=ABC_Section,\
    DIR1/workDir/sec1/subSec1/File1,\
    DIR1/workDir/sec2/File2,\
    DIR1/workDir/sec3/File3,\
    DIR1/workDir/lib,\
    DIR1/OTHER
<for list="${constituents}" param="myparam">
    <sequential>
        <if>
            <matches string="@{myparam}" pattern="^DIR1/workDir/.+" casesensitive="false" />
            <then>
                <!-- deal with your property -->
                <echo>@{myparam}</echo>
            </then>
        </if>
    </sequential>
</for>