Update: I am using Ant 1.8.1 on Windows XP.
I am trying to write an Ant master build file for multiple projects. I can successfully create a jar for each project, and I want to package all of these jars into a single tar.gz file. Each jar file is located within the bin subdirectory of its respective project, but this path could be changed in the future. I’ve tried something like this:
<tar destfile="foo.tar.gz" compression="gzip" >
<tarfileset dir=".">
<include name="**/*.jar" />
</tarfileset>
</tar>
…which kind of works. The only problem is that it maintains the directory structure within the jar. I want a flat file. So instead of:
foo.tar.gz
project1
bin
project1.jar
project2
bin
project2.jar
etc...
I need:
foo.tar.gz
project1.jar
project2.jar
I attempted to use Ant’s copy task to copy these jar files to a temporary directory and then tar them from there. However, the copy operation replicates paths within the target directory. So, same problem.
I think you’re almost there, having assembled a flattened directory of your files. What remains is to get rid of the
tarfilesetelement, which is there specifically for preserving/inserting structure. I thinktarandziptasks work fine with embeddedfilesetelements.The documentation bears me out on this – up until 1.7
filesetwas the embedded resource element that could be used in place oftarfileset.Come to think of it, I think that once you switch to
fileset, you may no longer need to temp-copy your files for flattening.EDIT:
I just built and ran this buildfile:
and there was no trace of the original directory in the archive:
Also,
tar -xvf tartest.tardumped the tarred files in my current directory.So… what are you doing differently that is causing different results for you?
EDIT 2:
More insight gained from re-reading your question. I’d completely sidestepped the problem of source paths generated by
**/*wildcards.Since you’re already considering copying those jar files to a temporary directory, all that’s missing is to use the
flattenattribute on thecopytask. That should fix you up.