tags:

views:

229

answers:

2

I don't want ant's jar task to notify me every time it skips a file because the file has already been added. I get reams of this:

 [jar] xml/dir1/dir2.dtd already added, skipping

Is there a way to turn this warning off?

A: 

I don't know of any options on the jar task to suppress these messages, unless you run the whole build with the -quiet switch, in which case you may not see other information you want.

In general if you have lots of duplicate files it is a good thing to be warned about them as a different one may be added to that which you expect. This possibly indicates that a previous target of the build has not done its job as well as it might, though obviously without more details it is impossible to say.

Out of interest why do you have the duplicate files?

Rich Seller
I am collapsing several directories of XML files down to one in creating the jar. The duplicates are DTDs.Basically:*/xml/data/*.{xml,dtd} -> data.jar (files named in jar as xml/data/*.xml)*/xml/params/*.{xml,dtd} -> params.jar (files named in jar as xml/params/*.xml)I'm tinkering with an existing system that already does this, and I need to retain the same structure as much as possible. I just need to build it with ant instead of horrible custom code.
skiphoppy
That didn't come out right - read an asterisk before /xml/data and /xml/params and you'll have what I typed. :)
skiphoppy
+1  A: 

This is an older question, but there is one obvious way to exclude the duplicates warning, do not include the duplicate files. You could do this in one of two ways:

  1. Exclude the duplicate files in some fashion, or
  2. Copy the files to a staging area, so that the cp task deals with duplicates, not the jar task.

So, instead of doing:

<jar destfile="${dist}/lib/app.jar">
  <fileset dir="a" include="xml/data/*.{xml,dtd}"/>
  <fileset dir="b" include="xml/data/*.{xml,dtd}"/>
  <fileset dir="c" include="xml/data/*.{xml,dtd}"/>
</jar>

do one of:

<jar destfile="${dist}/lib/app.jar">
  <fileset dir="a" include="xml/data/*.{xml,dtd}"/>
  <fileset dir="b" include="xml/data/*.xml"/>
  <fileset dir="c" include="xml/data/*.xml"/>
</jar>

or

<copy todir="tmpdir">
  <fileset dir="a" include="xml/data/*.{xml,dtd}"/>
  <fileset dir="b" include="xml/data/*.{xml,dtd}"/>
  <fileset dir="c" include="xml/data/*.{xml,dtd}"/>
</copy>
<jar destfile="${dist}/lib/app.jar">
  <fileset dir="tmpdir" include="xml/data/*.{xml,dtd}"/>
</jar>
<delete dir="tmpdir"/>

Edit: Base on the comment to this answer, there is a third option, although it is a fair bit more work... You can always get the source to the jar task, and modify it so that it does not print out the warnings. You could keep this as a local modification to your tree, move it to a different package and maintain it yourself, or try to get the patch pushed back upstream.

Paul Wagland
I emphatically don't want any staging areas. I am trying to get rid of too many staging areas right now.
skiphoppy