Ant 在'处的非法值;文件匹配';:模式集{includes:[Index.*.xml]排除:[]}
我必须从文件索引*.xml中搜索给定字符串“OK”。这*是随机生成的Id。此文件每15秒生成一次 这是我到目前为止所做的,但是我得到了异常“filematch处的非法值”:patternSet{includes:[Index.*.xml]excludes:[]}Ant 在'处的非法值;文件匹配';:模式集{includes:[Index.*.xml]排除:[]},ant,Ant,我必须从文件索引*.xml中搜索给定字符串“OK”。这*是随机生成的Id。此文件每15秒生成一次 这是我到目前为止所做的,但是我得到了异常“filematch处的非法值”:patternSet{includes:[Index.*.xml]excludes:[]} 任何关于这里有什么问题的建议,或者如果不可行,可能是另一种方法。 谢谢 新代码: 用这个 <path id="pathtoIndexfile"> <fileset dir="${destination.di
任何关于这里有什么问题的建议,或者如果不可行,可能是另一种方法。
谢谢
新代码:
用这个
<path id="pathtoIndexfile">
<fileset dir="${destination.dir}">
<include name="Index_*.xml"/>
</fileset>
</path>
<target name="wait-for-some-time">
<echo>${destination.dir}</echo>
<waitfor maxwait="1" maxwaitunit="minute" timeoutproperty="notfound">
<resourcecontains refid="pathtoIndexfile" substring="OK" />
</waitfor>
<antcall target="success" />
</target>
${destination.dir}
1) 例外情况是“java.lang.ClassCastException:org.apache.tools.ant.types.Path不能强制转换为org.apache.tools.ant.types.Resource”。2) 对于fileSet,例外情况是“java.lang.ClassCastException:org.apache.tools.ant.types.fileSet不能强制转换为org.apache.tools.ant.types.Resource”
我丢了一些罐子吗 我通过以下两个步骤实现了解决方案:
destination.dir为:${destination.dir}
确定存在:${OK.exists}
我删除了建议使用文件集的初始答案,这是错误的,因为资源包含
需要单个资源。我后面的回答使用了restrict
和resourcecount
,但除非您知道文件名,否则不会起作用-这是因为如果没有内置缓存,就无法获得fileset
的模式匹配。因此,在初始扫描之后,您不会看到任何添加到目录中的文件。
<path id="pathtoIndexfile">
<fileset dir="${destination.dir}">
<include name="Index_*.xml"/>
</fileset>
</path>
<target name="wait-for-some-time">
<echo>${destination.dir}</echo>
<waitfor maxwait="1" maxwaitunit="minute" timeoutproperty="notfound">
<resourcecontains refid="pathtoIndexfile" substring="OK" />
</waitfor>
<antcall target="success" />
</target>
<target name="StringSearch">
<sleep seconds="10"/>
<copy tofile="${destination.dir}/output.xml">
<fileset dir="${destination.dir}">
<include name="Index_*.xml"/>
</fileset>
</copy>
<sleep seconds="10"/>
<echo>destination.dir is: ${destination.dir}</echo>
<loadfile property="OK.exists" srcfile="${destination.dir}/output.xml">
<filterchain>
<linecontainsregexp>
<regexp pattern="OK"/>
</linecontainsregexp>
</filterchain>
</loadfile>
<echo>OK exists: ${OK.exists}</echo>
</target>