Java Cookbook Recipe CH.x - Automating Build Date, Version, etc.

Problem

You want to store build date, incremental build number, and version numbers into code for use in, e.g., a "Help About" dialog.

Solution

Use Ant (see 1.7), with the element and some variables.

Discussion

Standard approach using Ant, which you are presumably (or should be) using to package your jar files.

        <target name="version">
        <exec outputproperty="datestr" executable="date">
                <arg value="+%B %e, %Y"/>
		</exec>
		<buildnumber/>
		<echo file="src/jabadex/main/JDVersion.java">

                // This file was generated by build.xml, do not edit!
                package jabadex.main;
                public class JDVersion {
                        /** JabaDex major release version */
                        public final static String VERSION =
                                ${VER_MAJOR} + "." + ${VER_MINOR} + "." + ${VER_POINT};
                        public final static String BUILDDATE = "${datestr}";
                        public final static String BUILDNUMBER = "${build.number}";
                }
        </echo>
        </target>

Discuss buildnumber task.

Give helpAbout() code using this.