Doran
Doran

Reputation: 4090

Ant zipfileset for each element in a filelist

Using stock ant, is it possible to use a zipfileset for each element in a filelist? I'm looking for a way to specify the list of jars I'm using once and then be able to specify it as the classpath and as the files to deploy in my own jar.

This is the fastest way to build my release jar and include all the class files, but it requires specifying each jar as a zipfileset

<jar destfile="release.jar">
    ... my files ...
    <zipfileset src="jar/exampleA.jar" includes="**/*.class"/>
    <zipfileset src="jar/exampleB.jar" includes="**/*.class"/>
</jar>

I would prefer to specify it something like this:

<filelist id="proj.jars" dir="jar">
    <file id="exampleA" name="exampleA.jar"/>
    <file id="exampleB" name="exampleB.jar"/>
</filelist>

<jar destfile="release.jar">
    ... my files ...
    <!-- for each jar in proj.jars -->
        <zipfileset src="${jar}" includes="**/*.class"/>
</jar>

I do have a working solution, but it is significantly slower (4 or 5 times slower)

<jar destfile="release.jar">
    ... my files ...
    <restrict>
        <name name="**/*.class"/>
        <archives>
            <zips>
                <filelist refid="proj.jars"/>
            </zips>
       </archives>
    </restrict>
</jar>

A related question can be found here, but uses zipgroupfileset and that can't be used to exclude files from within the zip files.

Upvotes: 2

Views: 559

Answers (1)

ICR
ICR

Reputation: 14162

It's slightly crazy how long using the restrict/archive/zips version takes.

Our current solution is to unjar them to a temporary directory and include them via a zipfileset:

<unjar dest="${include-in-jar.tmpdir}">
    <patternset><exclude name="**/*.MF"/></patternset>
    <path refid="include-in-jar.classpath" />
</unjar>
<war ...>
    <zipfileset dir="${include-in-jar.tmpdir}" includes="**/*" />
</war>

This takes 4 seconds as opposed to the 40 that restrict/archive/zips takes.

Upvotes: 1

Related Questions