How to fail on pathelement not exists in apache ant?

倾然丶 夕夏残阳落幕 提交于 2019-12-13 05:58:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!