Pages

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;
}

Thursday, November 5, 2009

Absolute Path in J2EE Application


String jarFilePath = Thread.currentThread().getContextClassLoader().getResource("../lib/javax.jar").getPath().replaceAll("%20", " ");