Ben
Ben

Reputation: 6887

ANT: Copy contents of multiple filesets with same files in order of priority

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.

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:

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:

I want files in /bin to always take priority.

So in the example:

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.

Upvotes: 3

Views: 8520

Answers (2)

Vladimir
Vladimir

Reputation: 6871

It sounds to me like a very bad idea because if you have problems they will be time consuming to find out. But if you really want to do it here's a possible solution

<war [...] duplicate="preserve">
    [...]
    <classes dir="bin"/>
    <classes dir="build/classes"/>
</war>

Upvotes: 1

Spike
Spike

Reputation: 664

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>

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

Upvotes: 3

Related Questions