Say this doesn't sound like best practice, but let me explain. During assembly, we need to insert the assembly number and version of the system into a class whose sole purpose is to contain these values ββand make them available.
Our first idea was to use the properties of the system, but due to the volatility of the deployment environment (another way of saying that system administrators do strange, wicked, creepy things), we would like them to be hard-coded.
In fact, I see 4 possibilities to achieve this in ant:
use <replace> in the token in the class
The problem with this approach is that the file was modified, so you need to replace the token after compilation with <replaceregexp> ... sooo ugly, I don't want to touch the source code with a regular expression. Plus time dependencies.
copy the file, replace it with a copy, copy the copy, delete the copy
One must remember the sequence - the original class must be compiled first in order to be overwritten by the copy. Temporal dependencies are also ugly.
copy the file, replace the token on the original, compile, replace the shaded original with a copy
The same time dependency problem if it is not included in the compilation target. Which is also ugly because all of our build files use the same imported compilation target.
create the file from scratch in the assembly script / save the file outside the source path
It is an improvement over the first three because there are no time dependencies, but the compiler / IDE is very unhappy because it does not pay attention to the class. Red markers are terribly ugly.
What do you think of the alternatives?
Are there any recommendations for this?
I hope I skipped a perfectly reasonable approach.
thanks
EDIT We ended up using the manifest to save the build number and system version in the Implementation-Version attribute, without canceling MyClass.class.getPackage().getImplementationVersion() . I found this solution to be one of the answers to this thread , which was posted in a comment by andersoj
source share