For supporting purposes I need to add a version and build identifier to our Java library. The library itself is a toolkit without user interaction which is used in different environments (stand alone Java applications, web applications, Eclipse applications, Maven dependency, ...).
What I want, is a class with some constants giving me the above described information (such as MyAppVersion.BUILD
, ...), so that they can be shown e.g. in dialogs, command line output, etc. After my research, there seem to be the following approaches:
- add versioning to file name, such as
myLibrary-0.1.2.jar
; not feasible in our case, since I have no control over the file name when deployed - add information to the
MANIFEST.MF
and read it programmatically, like described here. I'm not sure however, how robust this approach is in respect to different class loaders (Eclipse, OSGi, application servers, ...) and if the JAR file gets re-packaged, this information is lost - use a
version.properties
file holding the version, as described here and use a script during build to update theversion.properties
file - hard code the version information into the class directly and use a script to update this information
Are there any other approaches? The last option seems most "robust" to me, are there any objections against this variant? Is there a Maven plugin which would support updating this information in a MyAppVersion.java
file during build?