问题
the ant-contrib lastest version is ant-contrib-1.0b3.jar
?
http://ant-contrib.sourceforge.net/tasks/tasks/more_conditions.html
this document show endsWith
condition
But I use ant 1.8.2 And ant-contrib-1.0b3.jar
, I cann't find the endsWith
condition
<if>
<endswith string="D:\FeiLong Soft\Essential\Development\repository\org\springframework\spring-beans" with="spring-beans" />
<then>
<echo>equals</echo>
</then>
<else>
<echo>not equals</echo>
</else>
</if>
But result:
BUILD FAILED
E:\Workspaces\feilong\feilong-platform\tools\feilong-tools-ant\build.xml:32: if
doesn't support the nested "endswith" element.
Total time: 1 second
回答1:
When checking the sources from antcontrib (version 1.0b2 or 1.0b3) especially net/sf/antcontrib/antcontrib.properties
and ../antlib.xml
you'll see, there is no startsWith
or endsWith
condition, though it's mentioned in the antcontrib manual.
Those two conditions originate from the Antelope project, which provides a UI for running ant and several ant tasks. Years ago there were plans to merge Antelope with AntContrib, see Antelope Tasks Merging with AntContrib and Antelope project site :
The Antelope Project also provides a set of additional tasks that provide functionality not found in the standard tasks distributed with Ant. Work is underway to merge the Antelope tasks with the AntContrib project.
[...]
The Ant-Contrib project is a collection of tasks (and at one point maybe types and other tools) for Apache Ant. Some of the Antelope tasks are now part of that project.
But somehow those merging plans stagnated and never finished properly, also Antcontrib seems to be dead - latest release 1.0b3 from 2006-11-02
Anyway, you may either use the ant matches condition with antcontrib :
<project>
<!-- Import AntContrib -->
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="foo" value="D:\FeiLong Soft\Essential\Development\repository\org\springframework\spring-beans"/>
<if>
<matches string="${foo}" pattern="^.+spring-beans$"/>
<then>
<echo>equals</echo>
</then>
<else>
<echo>not equals</echo>
</else>
</if>
</project>
or the Antelope ant tasks.
回答2:
I had the same problem using "startwith" and dont found a solution. I don't understood the cause of "contains" working, but "startwith" and "endwith" don't.
<if>
<contains string="a sample string" substring="sample" />
<then>
<echo>match</echo>
</then>
<else>
<echo>not match</echo>
</else>
</if>
来源:https://stackoverflow.com/questions/13670197/use-ant-contrib-how-to-use-endswith