I have an application used in clustering so that it is available if one or more failures, and I want to implement a way to check jar file version in java.
I have this piece of code for this (for example: in the MyClass class):
URLClassLoader cl = (URLClassLoader) (new MyClass ())
.getClass().getClassLoader();
URL url = cl.findResource("META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(url.openStream());
attributes = manifest.getMainAttributes();
String version = attributes.getValue("Implementation-Version");
When I run jar as an application, it works fine, but when I use the jar file as librairie in another application, I get the version number of another application.
So my question is: how can I get the jar manifest where MyClass is contained?
NB: I am not interested in a solution using static constraints such as 'classLoader.getRessource ("MyJar.jar")' or a file ("MyJar.jar")