Execute Ant action always and independently from target

白昼怎懂夜的黑 提交于 2019-12-10 19:50:35

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2318217/execute-ant-action-always-and-independently-from-target

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