I’m not sure if this is a common knowledge thing that I’ve not picked up in the past but here we go… For those of us who have used C and C++ the idea of having a string generated based on the compilation date of the code is pretty normal. Its really useful for identifing the version of the software the end user has. In C this is done with a preprocessor macro that gets converted into today date.
I’ve been wanting something like this for Java for a while and this morning I had an idea which I’m now using happily. I simple grab the date of the “main” class file from my game java like this:
URL versionUrl = getClass().getClassLoader().getResource("org/newdawn/grav2/GameWindow.class");
try {
// update the title of the window based on the version
title += " ("+new Date(versionUrl.openConnection().getLastModified())+")";
} catch (Exception e) {
title += " (Version Undetermined)";
}
Maybe theres a better way that I don’t already know about? I quite like this tho since it gives you a different date even if you just repackage your jar.
Kev