开发者

In an Ant build script, how do you check for the existence of a file or directory as a dependency for a task?

Getting started on writing my first build s开发者_如何学JAVAcript. I dont get the whole dependency thing. This kind of make sense when your compiling say java and you need the object files to create a jar. But what about if you just want to verify the existence of any file or directory thats not part of a compile task?

Ive been able to use available but I dont know how to use the result of that as a dependency for a task


With something like this:

<project name="foo-bar" basedir=".">
    <target name="bar" depends="foo" unless="isAvailable">
     <echo message="file is not available" />
    </target>

    <target name="foo">
      <available file="${basedir}/path/to/file.java" property="isAvailable"/>
    </target>
</project>
  • The "bar" target depends on the "foo" target.
  • When "foo" is executed, it checks for the presence of the file.
  • If it exists, it sets the isAvailable property.
  • The "bar" target will only execute and echo the message if isAvailable is not set.

You can also put the <available> at the "root level" of your build(outside of a target, as a direct child of the <project> and it will get evaluated before any of the targets are run:

<project name="foo" basedir=".">

    <available file="${basedir}/path/to/file.java" property="isAvailable"/>

     <target name="bar" unless="isAvailable">
     <echo message="file is not available" />
    </target>
</project>


If you want to test if a file exists, look at available

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜