Mehotd to read Jar versions

I have a test JSP that is used for testing the installation of the applicaiton. 
I that I needed to find the versions of the Jar files that are loaded by the server. I wrote a small method in a JSP to read the Versions from the JAR files. 


String readManifest(String jar) {
try {
JarFile jarfile = new JarFile(jar);
Manifest manifest = jarfile.getManifest();
java.util.Map map = manifest.getEntries();
java.util.Iterator iter = map.keySet().iterator();
String ver = "unknown";
while(iter.hasNext()){
String key = (String)iter.next();
String str = null;
java.util.jar.Attributes attr = (Attributes)map.get(key);
str = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if(str == null) {
str = attr.getValue(Attributes.Name.SPECIFICATION_VERSION);
}
if(str != null) { ver = str; }
else {
ver = "unknown";
}
}
return ver;
} catch (Exception ex) {
return "Error:"+ex.getMessage();
}
}