在 Ant 中,如何测试属性是否以给定值结尾? [英] In Ant, how can I test if a property ends with a given value?

查看:28
本文介绍了在 Ant 中,如何测试属性是否以给定值结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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 否则.您可以在 任务的 ifunless 参数中使用它.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆