aspose file tools*
The moose likes Java in General and the fly likes injecting a value into a variable from a build process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "injecting a value into a variable from a build process" Watch "injecting a value into a variable from a build process" New topic
Author

injecting a value into a variable from a build process

Stuart Rogers
Ranch Hand

Joined: Oct 02, 2008
Posts: 139
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

Joined: Nov 09, 2011
Posts: 1021
    
    5

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

Joined: Oct 02, 2008
Posts: 139
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

Joined: Oct 27, 2005
Posts: 19696
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Stuart Rogers
Ranch Hand

Joined: Oct 02, 2008
Posts: 139
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

Joined: Aug 05, 2005
Posts: 3566
    
  15
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.


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: injecting a value into a variable from a build process