Copying files from one JAR to another using ANT

To avoid needless duplication of source files in two different repositories, I would like to write an Ant build.xml file that copies files from one .jar file to another. I don’t want to copy everything in the source jar, just certain selected files.

Now I could certainly use the unjar task to extract everything from the jar into a temporary directory, then use a copy task to copy the files to the directory from which the new jar will be built, then use a delete task to remove the temporary directory. However is there anything simpler?

In particular, is there a way to treat a jar (or, for that matter, a zip or a tar) as a directory tree from which files can be copied without making temporary copies first? For instance, could I set the src attribute of the copydir element to a jar file instead of an actual directory?

4 Responses to “Copying files from one JAR to another using ANT”

  1. Mik Says:

    ( is your friend!

  2. Todd Gayley Says:

    Use (

  3. Alexandre Rafalovitch Says:

    Is anything wrong with ZipFileSet for your needs? (

    If that does not work out, maybe a FileSet adapter can be created on top of the TrueZip library:

  4. Carey Evans Says:

    I think you’re looking for the zipfileset element on the zip task, and presumably also jar.

Leave a Reply