We have a library that gets released with a different version number every couple of weeks. The problem is that in order to store the version number in our jars we have a version.txt file that just contains the version number and then gets included into the build. This seems like the wrong way to do this but I can’t come up with a better solution. What is a better way to store the version number in our jar’s so that if a user calls me up I can easily find out the version of our product they are using?
We have a library that gets released with a different version number every couple
Share
Firstly — make sure your program or tool can some SHOW the version number. But where does it come from? We include it in the build.
Just make sure it’s visible someplace when they run it! If there’s nothing runnable, add a Main, and make it the Main-Class, that just prints the version. Then you can say, Please type
java -jar YourLibrary.jar, and it just runs main and prints your version.Here’s the beginnings of the code to read resources out of your jar, from inside the jar, if the resource (such as Version.txt) is next to klazz:
I like to make it automatic in every build, so I don’t forget to bump it. Rather than a text file, I use .properties… but you could do the same thing in Version.txt.
(Actually, at the moment, we include just the build-time. But the idea is the same.)
I do it like so — I have a Version.properties file, with:
And as part of the ANT script, we do:
Note — the above is a bit platform specific, but you get the idea.
And how you read .properties files, it’s another little pile of code but easy enough.