始终独立于目标执行 Ant 操作 [英] Execute Ant action always and independently from target

查看:23
本文介绍了始终独立于目标执行 Ant 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法指定像<copy>这样的动作?在每次构建文件被 ant 读取时执行的 Ant 构建文件中(无论调用哪个目标)?

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)?

背景是:我想要一个 *.properties-file 在它不存在时从模板自动创建.我知道,我可以指定一个执行此操作的目标,然后将其包含在依赖关系树的根目录中,但也许有更优雅的解决方案.因为实际上问题有点复杂:读取 *.properties-file 的 ant 文件是由其他构建文件导入的,我不想在它们之间交叉引用目标.

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.

这是我第一次在这里发帖.希望您能提供帮助 - 来自德国的问候,Ben.

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

推荐答案

只需将代码放在文件的顶部,在目标定义之外.

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>

在这种情况下,echo 将在任何目标之前执行一次,无论调用哪个目标.

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

这篇关于始终独立于目标执行 Ant 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆