(netbeans 6.1, external ant 1.7)

Here is a code snippet from build.xml which shows a possible way to customize your build in Netbeans by providing a version number and including it into the MANIFEST.MF of the created distribution jar. The current property version will be stored in a version.properties file. This version number will be retrieved and written back to the file. The script knows then the new version number (custom.version.property) and uses it in the jar creation task (see also Adaptation of Netbeans Ant Build for Integration – CopyLibs Issue).

Dealing with version number:

  <!--
                =================
                Set Version Related
                =================
     -->
     <!-- watch out! if you put version.properties file to src dirs,
     cause the file ist copied 
     to build before it is touched by this tasks, 
     you will probably need to do some further customization -->
     <property name="custom.version.file" value="${basedir}/version.properties"/>
    <target name="-post-init">
        <!-- check if there is a version -->
        <available file="${custom.version.file}" property="custom.version.available"/>
    </target>
    <target name="pre-inc-version" depends="init"  unless="custom.version.available">
        <echo message="No version file found. Creating ${custom.version.file} with Initial Version 0."/>
        <echo file="${custom.version.file}" message="version=0"/>
    </target>
     <target name="inc-version" depends="pre-inc-version">
         <!-- increment version number -->
        <propertyfile file="${custom.version.file}">
            <entry key="version" value="1" type="int" operation="+"/>
        </propertyfile>
        <!-- read version -->
        <property file="${custom.version.file}" prefix="custom"/>
        <echo message="project ${ant.project.name} released with version ${custom.version}" />
    </target>
    <target name="-pre-jar" depends="inc-version">
        <!-- Empty placeholder for easier customization. -->
        <!-- You can override this target in the ../build.xml file. -->
    </target>
    <target name="clean-version" depends="-do-clean" description="Remove version property file">
        <delete file="${custom.version.file}"/>
    </target>

(You could also use ant BuildNumber task.)

Using the version number in jar file creation:

<!--
                =================
                Jar Overriding Default
                =================
     -->
     <target depends="init,compile,-pre-jar,-post-jar" description="Custom Build JAR with libs and version. See -do-jar-with-libs." name="jar">
        <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
        <echo message="-------------run.classpath------- ${run.classpath}"/>
        <echo message="--------- build.classes.dir.resolved ------ ${build.classes.dir.resolved}"/>
        <pathconvert property="run.classpath.without.build.classes.dir">
            <path path="${run.classpath}"/>
            <map from="${build.classes.dir.resolved}" to=""/>
        </pathconvert>
        <echo message="-------- run.classpath.without.build.classes.dir ---- ${run.classpath.without.build.classes.dir}"/>
        <pathconvert pathsep=" " property="jar.classpath">
            <path path="${run.classpath.without.build.classes.dir}"/>
            <chainedmapper>
                <flattenmapper/>
                <globmapper from="*" to="lib/*"/>
            </chainedmapper>
        </pathconvert>
        <echo message="--- build.classes.dir --- ${build.classes.dir}" />
        <copy todir="${dist.dir}/lib" flatten="true">
            <path>
                <pathelement path="${run.classpath.without.build.classes.dir}"/>
            </path>
        </copy>
        <j2seproject1:jar manifest="${manifest.file}">
            <j2seproject1:manifest>
                <j2seproject1:attribute name="Main-Class" value="${main.class}"/>
                <j2seproject1:attribute name="Class-Path" value="${jar.classpath}"/>
                <j2seproject1:attribute name="Build-Version" value="${custom.version}" />
            </j2seproject1:manifest>
        </j2seproject1:jar>
        <echo>To run this application from the command line without Ant, try:</echo>
        <property location="${dist.jar}" name="dist.jar.resolved"/>
        <echo>java -jar "${dist.jar.resolved}"</echo>
    </target>