I have this variable in a class containing the main() for my app
I have a MySQL stored procedure that generates guaranteed-to-be-unique random serial numbers.
I'd like to set up my build-process such that this s.p. gets called and the value returned be injected
into serialNumber automatically. The goal here is for each compilation of my app gets a unique serial number.
Is this possible? and if so, how? As always, suggestions, ideas, positive criticism and especially examples are most welcome.
I take it you actually mean for each execution of the app?
Joined: Oct 02, 2008
for each individual jarfile generated by building the app, yes.
Each time I build the app I want the resulting jarfile to contain a new, unique serial number stuffed assigned as the value of serialNumber.
I managed to this not in Java code but with a property file, updated by Ant when I use it to build the JAR file.
I have a build.properties file in the root of my project, together with my build.xml file. I then have this as my JAR Ant task:
I then read this version number from code like this:
My versions are now Strings like "2011-12-01 b4", "2011-12-01 b5", "2011-12-02 b6", etc.
A properties file eh? A clever insight, I shall try it.
In a C++ world, perhaps one could create an .exe that directly injected the serial number into the target .exe at a specific byte offset corresponding to where the serialNumber was stored in the mapping table, but that's crawling way past my speed.
Does it have to be in the code ? What about the jar manifest. There are various standard fields allowed by the jar file specification that might suit your purpose or you could just add your own field. It's should be fairly easy to get your build process to generate a manifest file that you include in the jar.
subject: injecting a value into a variable from a build process