You can use Ant build tool (http://ant.apache.org/) to create property file with current date, include it in jar file and then read this date from file.
Ant script to create property file with current date will look like:
<propertyfile file="resources/builddate.properties">
<entry key="builddate" value="now" type="date" pattern="yyyy.MM.dd HH.mm.ss"/>
</propertyfile>
And here is java code to read build date.
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import org.apache.log4j.Logger;
public class ProgramUtil {
static Logger log = Logger.getLogger(ProgramUtil.class);
public static Date getBuildDate() {
Date retValue = null;
try {
Properties p = new Properties();
InputStream is = ProgramUtil.class.getResourceAsStream("/builddate.properties");
if (is != null) {
p.load(is);
String buildDateString = p.getProperty("builddate");
try {
retValue = buildDateString == null ? null : new SimpleDateFormat("yyyy.MM.dd HH.mm.ss").parse(buildDateString);
} catch (ParseException e) {
log.error("Error", e);
}
}
else {
log.error("Resource builddate.properties is not found");
}
} catch (IOException e) {
log.error("Error", e);
}
return retValue;
}
}