Let’s say that my project has a main class. I’d love to have
public static final String version = "0.0.0.1";
However, I don’t want to have to manually set the version, as my ant build file has the version present. Is there any way to insert this value based on the value present in the build file?
The easiest thing to do would be to write the version number out to a property file (or alternatively the Manifest file) using Ant, and in your Java code read the value of that field from the property file instead of hard-coding it.
It’s of course possible to add the field to the class before (by changing the source file) or after compilation, but that’s probably unneeded effort and might result in hard-to-version source code.