Apache Ant – Adding a file to an existing zip archive

I recently needed to add a file to an existing WAR as part of an Ant build step. The Ant docs are not really clear on whether this is possible and there certainly isn’t an example.

This is the method I used:

<target name="dist" depends="build">
	<zip destfile="${rootBuildDir}/import/MyWebApp.war" update="true">
		<zipfileset dir="${distDir}" 
			includes="*.jar" prefix="WEB-INF/lib/"/>

As you can see I’ve used the generic zip task but the technique works for WAR, and JAR files too, since they are just zip files.

See the Ant docs for more info about the zip task and zipfileset type.

Edit: 2012-12-21 Updated link to ANT docs

4 thoughts on “Apache Ant – Adding a file to an existing zip archive”

Leave a Reply

Your email address will not be published. Required fields are marked *