Get version of WAR file on manifest.
807603Oct 23 2007 — edited Nov 13 2007Hi there. I have a problem to read a key of the manifest file. I have a client-server application in which I need to read both versions (client and server). I decided to place the versions as keys on the manifest.mf file. To do it on the client part (JAR file) was easy:
public String getClientVersion(){
try {
Class cls = Class.forName ( "com.sismed.principal.IWG2" );
ProtectionDomain pDomain = cls.getProtectionDomain();
CodeSource cSource = pDomain.getCodeSource();
URL loc = cSource.getLocation();
JarFile jar = new JarFile ( new File(loc.getFile()) );
Manifest manifest = jar.getManifest();
Attributes attrs = (Attributes) manifest.getMainAttributes();
String clienteVersion = attrs.getValue("Specification-Version");
return clienteVersion;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "Impossible to detect version";
}
Note that it is necessary to pass the program's main class as a parameter to get the variable cls. In this case, IWG2.class that is on the path com.sismed.principal.IWG2
But, on the server, the file is a WAR file. So it do not have a main class, and I cannot fill the cls variableto read the server's manifest file. What can I do? I've heard that you can use the web-xml file to get the version of WAR files, but is that the right thing to do on WAR files? Or should I use the manifest file?
Sorry about my english.
Best regards.