Pages

Showing posts with label Jar File Version. Show all posts
Showing posts with label Jar File Version. Show all posts

Monday, November 9, 2009

How to Check Jar File Version

To have access to the version of a jar file, you should have access to the jar file. Precisely, you need to take a look at the jar file's manifest.

In case of the J2EE application

String checkjarFilevesion() {
try {
if(logger.isInfoEnabled())
logger.info("Verifying Jar Version");
String jarFilePath = Thread.currentThread().getContextClassLoader().getResource("../lib/javax.jar").getPath().replaceAll("%20", " ").toString();
JarFile jarfile = new JarFile(jarFilePath);
//Implementation-Version: 3.2.6.SP1
Manifest manifest = jarfile.getManifest();
String version = manifest.getMainAttributes().getValue("Implementation-Version");
return version;
} catch (IOException e) {
// TODO Auto-generated catch block
if(logger.isInfoEnabled())
logger.info("Invalid JAR file path");
}
return null;
}