在 Ant 中,如何测试属性是否以给定值结尾? [英] In Ant, how can I test if a property ends with a given value?
问题描述
在 Ant 中,如何测试属性是否以给定值结尾?
In Ant, how can I test if a property ends with a given value?
例如
<property name="destdir"
value="D:\FeiLong Soft\Essential\Development\repository\org\springframework\spring-beans" />
如何测试 ${destdir}
是否以 "spring-beans"
结尾?
how can I test if ${destdir}
ends with "spring-beans"
?
附加:
在我的ant-contrib-1.0b3.jar中,没有'endswith'任务~~
In my ant-contrib-1.0b3.jar, without 'endswith' task~~
推荐答案
作为 Matteo,Ant-Contrib 包含了很多好东西,我经常使用它.
As Matteo, Ant-Contrib contains a lot of nice stuff, and I use it heavily.
但是,在这种情况下可以简单地使用
任务:
However, in this case can simply use the <basename>
task:
<basename property="basedir.name" file="${destdir}"/>
<condition property="ends.with.spring-beans">
<equals arg1="spring-beans" arg2="${basedir.name}"/>
<condition>
如果 ${destdir}
以 string 结尾,则属性
和 ${ends.with.spring-beans}
将包含 true
-beansfalse
否则.您可以在
任务的 if
或 unless
参数中使用它.
The property ${ends.with.spring-beans}
will contain true
if ${destdir}
ends with string-beans
and false
otherwise. You could use it in the if
or unless
parameter of the <target>
task.
这篇关于在 Ant 中,如何测试属性是否以给定值结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!