How to Create JARs with Ant
Ant provides the tasks Jar, SignJar and Manifest to help you create JAR files. Creating a JAR from the files in a directory is as easy as:
<jar destfile="${dist}/example.jar" basedir="${build}"/>
For more complex archives, filesets can be used and a manifest can be specified:
<jar destfile="${dist}/example.jar" manifest="${src}/manifest/MANIFEST.MF"> <fileset dir="${build}" excludes="**/test/*.class"/> <fileset dir="${src}/images"/> </jar>
Ant is also able of extracting and adding other JARs. The filesetmanifest attribute specifies what to do with their manifests (the default is to skip them):
<jar destfile="${dist}/example.jar" manifest="${src}/manifest/MANIFEST.MF" filesetmanifest="mergewithoutmain"> <fileset dir="${build}" excludes="**/test/*.class"/> <zipfileset src="${lib}/helper.jar"/> <zipfileset src="${lib}/util.jar"/> </jar>
Instead of providing a manifest file, you can also use Ant to generate one. You can either create a file with the Manifest task, or embed a manifest into your Jar trask:
<jar destfile="${dist}/example.jar"> <manifest> <attribute name="Main-Class" value="com.jarfiller.example.MainClass"/> <attribute name="Implementation-Title" value="Jarfiller Example"/> <section name="com/jarfiller/example"> <attribute name="Sealed" value="true"/> </section> <section name="com/jarfiller/helper"> <attribute name="Sealed" value="true"/> </section> </manifest> <fileset dir="${build}" excludes="**/test/*.class"/> <fileset dir="${src}/images"/> </jar>
To sign JARs with Ant, use the SignJar task:
<signjar jar="${dist}/example.jar" keystore="myKeystore" storepass="password" alias="myKey"/>
It is also possible to sign several JARs in a single task, and to create new JARs instead of modifying existing JARs:
<signjar destDir="signed" lazy="true" preservelastmodified="true" keystore="myKeystore" storepass="password" alias="myKey"> <path> <fileset dir="${dist}" includes="**/*.jar" /> </path> </signjar>

