问题
I have a really long class path using a <path />
section. On a different machine, lots of the jars dont exist. How can I check the pathelements all exist?
回答1:
Use the present selector :
<project>
<fileset dir="/home/rosebud/temp/dir1" includes="*.jar" id="srcfileset">
<present present="srconly" targetdir="/home/rosebud/temp/dir2"/>
</fileset>
<echo>Missing files => ${toString:srcfileset}</echo>
</project>
echoes all files only present in /home/rosebud/temp/dir1
If all files from /home/rosebud/temp/dir1 would be present in /home/rosebud/temp/dir2, the fileset would be empty.
If you need to finish your build in case of missing files use :
<project>
<fileset dir="/home/rosebud/temp/dir1" includes="*.jar" id="srcfileset">
<present present="srconly" targetdir="/home/rosebud/temp/dir2"/>
</fileset>
<fail message="Missing files => ${toString:srcfileset}">
<condition>
<resourcecount refid="srcfileset" when="greater" count="0" />
</condition>
</fail>
</project>
来源:https://stackoverflow.com/questions/12842640/how-to-fail-on-pathelement-not-exists-in-apache-ant