• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

injecting a value into a variable from a build process

 
Stuart Rogers
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings all:

environment: Eclipse/Java/MySql/Maven/WindowsXP

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.

TIA,

Still-learning Steve

 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve

The goal here is for each compilation


I take it you actually mean for each execution of the app?
 
Stuart Rogers
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


Thanks for your reply!


Still-learning Steve
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stuart Rogers
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thank you for your reply!

Still-learning Steve
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic