Ant Task check if a file exists

来源:互联网 发布:老死什么感受知乎 编辑:程序博客网 时间:2024/06/16 09:22
This is to remember what I learned when I customize Liferay SDK plugins.

In my case, I need to read a properties file and then get those values to create portlet. The first thing, I have to validate if the file exists in the folder.

1. Fail Task

<fail message="Files are missing."><condition><not><resourcecount count="1">                   <fileset dir="." includes="${properties.file.name}"/></resourcecount></not></condition></fail>
http://ant.apache.org/manual/Tasks/fail.html The link shows more examples of Fail task.

2. Available Task

<!-- If the file doesn't exist, it will display the message. --><if><not><available file="${properties.file.name}"/></not><then><echo message="${properties.file.name} doesn't exist." /></then></if>
https://ant.apache.org/manual/Tasks/available.html The link shows more examples of Fail task.



原创粉丝点击