JAR file creation using ANT

Author: Kasper B. Graversen, 12/12/07
Keywords: ANT, Build script
Abstract: This article explains best practices when creating JAR files using ANT.
subscribe to my RSS feed


Bookmark and Share


JAR file creation using ANT

A JAR file is no more than a ZIP file containing compiled java code and other resources such as images and sounds and a MANIFEST file. The manifest file, I have only used to define class paths to resources external to the jar file itself. This enables the class loader to load these resources along with the jar file rather than fetching these resources during running the application.
<target name="-init">
	<properties name="distro.version" value="1.0"/>
    <tstamp>
        <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
    </tstamp>
    <buildnumber file="build.num"/> <!-- let ANT auto increment a build number -->
</target>

<target name="distro" depends="-init, -compile"  description="creates a distribution jar file">
    <jar destfile="${distro.dir}/${distro.name}-${distro.version}.jar"
        basedir="${dir.build}"
        includes="**/*.class"
        update="true"
        duplicate="fail"
    >
        <manifest>
            <attribute name="Built-By" value="Kasper B. Graversen"/>
            <attribute name="Implementation-Version"  value="${distro.version}-build${build.number}"/>
            <attribute name="Built-Date" value="${TODAY}"/>
        </manifest>
    </jar>
</target>
See also http://ant.apache.org/manual/CoreTasks/jar.html for more info on the jar task.



Comments

If you have any comments to this article, please drop me a mail at firstclassthoughts at gmail dot com please indicate if I can't publish whole or parts of your comment on the site.


If you like this site consider subscribing to my RSS feed or how about subscribing by Email.


Help spread the word

Share this post on your favorite social bookmarking sites:
If you enjoyed this article, found it thought provoking, educative or otherwise good, please link to this page from your page or social bookmarking page. If you have any texts you think are worth publishing on First Class Thoughts, don't hesitate to send me a mail! Quality always welcome.


Bookmark and Share


The most recent contributions
28/07/09 Magic in mathematics II Fun with the number cyclic numbers, and specifically with 142857 as it is the smallest of such numbers.
13/07/09 My top 8 time-saving Firefox shortcuts This article presents my favorite top 8 time-saving shortcuts in Firefox 3.0 and Firefox 3.5. Get to know these and you'll be saving a lot of time. They have been ordered by "the element of most surprise"
20/05/09 Board Game Jungle speed / Arriba Review of the cool game "Jungle Speed" aka. "Arriba".
16/05/09 Danish Twin words "Twin words" are words that not only have multiple meanings, they must be composed next to each other in meaningful sentences. This article explores the concept of twin words.
Nothing of interest? Try browsing the entire article archive...