With our modern version control systems, we could assume we know for
every single release we make the exact source code revision that
corresponds. But, in the hurry of a bug found by your dear clients
(or your product owner), you can't find the corresponding tag in
your VCS, it will make the whole patch process really difficult. You
will have to find the exact revision, extract it and debug to patch
(or backport an existing patch).
I will explain a little trick to make the find the revision thing a
lot easier (I am assuming you're using maven to build your projects)
:
maven-buildnumber-plugin
Embed revision into artifacts
By using this plugin you can easily embbed revision informations into
your artifacts, the configuration is, as always with maven, as easy as
A-B-C, just add the following to your projects' pom :
We tell maven to use the maven-build-number plugin during the validate
phase and we add the property buildNumber to the manifest
entries of the ear and war we can produce (useful if we are in a
multimodule pom). This setup is performed under a specific profile and
can be triggered by executing maven this way :
If you look at resulting artifacts, the META-INF/MANIFEST.MF files
contain Implementation-Build: #### (where #### is the current revision
on your SCM).
Get revision number at runtime
Now that the revision is stored in our artifacts, we need a way to
figure out, at runtime, which revision is deployed, the basic idea is
to have a servlet get this info for us, and dump it on your web
browser. For confidentiality purpose, it might be useful to put an
authorization filter on top of this servlet, but it won't be covered
in this post. The code for the servlet follows :
Just mount this Servlet via your web.xml, add a filter on top and
you're gone. We assume that if the module is empty, we are at the root
of an EAR file. This is confirmed to work under Glassfish application
server, it might work with other application servers (path might need
to be corrected), anyway, I'd love to get feedback on this.
As an ancient Java developer, I’ve learned to use a set of
annotations to bring meta programming in my projects. Meta
programming can be ...…
Continue reading