tags:

views:

27

answers:

1

Hello all!

Is there a way to specify actions like <copy> in an Ant buildfile that get executed every time the build file gets read by ant (regardless of the target which is called)?

The background is: I want a *.properties-file to be automatically created from a template when it's not present. I know, I could specify a target which does this and then include it at the root of the dependency-tree but maybe there is a more elegant solution. Because actually the problem is a bit more complex: the ant file where the *.properties-file is read-out is imported by other build files and I don't want to cross-reference targets between them.

I hope I explained my problem sufficiently. In cases of questions do not hestitate to ask.

This is my first posting here. Hope you can help - Greetings from Germany, Ben.

A: 

Just put the code at the top of the file, outside of a target definition.

<project name="myproject" default="mytarget" basedir=".">

  <echo message="Hello there." />

  <target name="mytarget">
    <!-- Do stuff. -->
  </target>

  <target name="myothertarget">
    <!-- Do other stuff. -->
  </target>

</project>

In this case the echo will get executed once before any target, regardless of which target is invoked.

Dan Dyer
Thank you! I thought of this as well, but I didn't see the If-Task in content assist, that's why I thought it's not possible. But it turned out that the problem was I didn't include the ant-contrib.jar in the Ant plugin preferences of Eclipse and I forgot the necessary taskdef statement. Now everything's smooth.
Ben