Creating av version class


(jesper.holmberg) #1

We are currently using an Ant task in our build to create a property file which contains the current version of our project, so that this information can be accessed in runtime from our Java application. However, for architectural reason we are moving away from this type of property files, and I would thus like to create a Java class at build time which contains the version information, or alternatively put a version field within an existing class.

Has anyone done something similar and can share their ideas?


(Attila Kelemen) #2

I don’t know why you want to switch from properties file (you can write a class which reads from it and use that class). Creating a Java class at build time has some disadvantages: You won’t see that class in the IDE. What you should also be aware of that javac inlines compile time constants from fields (e.g., String constant). So if you have ‘static final String X = “1”’ in class A and use “X” in class B, if you rebuild and replace class A (changing X), B will still see X as “1”. Overwriting an existing class is problematic for VCS (assuming the file is checked in, otherwise it is the same as generating a new class).

So, I’d recommend not to use class this way, instead a properties file seems perfectly good to me, if accessing it is hidden by a class. I’m curious however what architecture requires you not to use a properties file?