ANT:按优先级顺序复制具有相同文件的多个文件集的内容 [英] ANT: Copy contents of multiple filesets with same files in order of priority

查看:20
本文介绍了ANT:按优先级顺序复制具有相同文件的多个文件集的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个 Web 应用程序,该应用程序从多个位置获取类文件.这些位置可以包含相同的类文件.我需要能够指定优先级,以便在复制类时某些位置优先于其他位置.

I'm trying to build a web application which takes it's class files from multiple locations. These locations can contain the same class files. I need to be able to specify a priority so that some locations take priority over others when copying the classes across.

我们有单独的 ant 脚本来构建 WAR 文件.这个构建是在我开发时在任何更改的类中进行热交换.所以这个构建必须很快.

We have separate ant scripts which build the WAR file. This build is to hotswap in any changed classes whilst I am developing. So this build must be quick.

比如我的两个上课地点是:

For example, my two class locations are:

  • /bin
  • /build/classes

我希望将这两个目录中的类复制到:/web/WEB-INF/classes

I want classes from both these directories to be copied to: /web/WEB-INF/classes

但是,如果这两个位置都包含相同的类文件,例如:

However, if both these locations contain the same class file, eg:

  • /bin/com/ben/Test.class
  • /build/classes/com/ben/Test.class

我希望/bin 中的文件始终优先.

I want files in /bin to always take priority.

所以在示例中:

  • 文件:/bin/com/ben/Test.class,将被复制.
  • 文件:/build/classes/com/ben/Test.class 将被忽略.

我当前的脚本如下所示:

My current script looks like this:

<sync todir="${deploy}/WEB-INF/classes" verbose="true">
    <fileset dir="bin"/>
    <fileset dir="build/classes"/>
</sync>

这可行,但每次运行脚本时,都会删除悬空文件.我也不确定这里是否可以保证任何优先级.

This works, but each time the script is run, dangling files are removed. I'm also not sure if any priority here is guaranteed.

如有任何帮助,我们将不胜感激.

Any assistance would be appreciated.

推荐答案

所谓的悬空文件被移除,是指已经在${deploy}/WEB-INF/classes"目录中的文件吗?

By dangling files being removed, do you mean files which are already in your "${deploy}/WEB-INF/classes" directory?

同步将清除目标目录中的现有文件,如果您不希望发生这种情况,我建议使用复制.

Sync will clear existing files in the target directory, if you don't want that to happen, I would recomend using copy instead.

对于具有更高优先级的文件夹,您可以多次复制并覆盖现有文件.

As for having a folder with a higher priority, you could just copy multiple times and overwrite existing files.

  <copy todir="${deploy}/WEB-INF/classes" verbose="true">
    <fileset dir="build/classes"/>
  </copy>

  <copy todir="${deploy}/WEB-INF/classes" verbose="true"  overwrite="true">
    <fileset dir="bin"/>
  </copy>

现在,test.class 将从 build/classes 复制,然后被 bin 中的 test.class 覆盖.

Now, test.class will be copied from build/classes then overwritten by test.class from bin.

这篇关于ANT:按优先级顺序复制具有相同文件的多个文件集的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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