My contemplations and diurnal novelties are publicized here

Archive for November, 2014

How to get Executing Jar Name and Modified Date in Java


Following is the piece of code to get your executing Jar name and its modified date. You can use these info for logging purpose:-

// Get File Jar File

String jarFileName = new java.io.File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName();

JarFile jf = new JarFile(jarFileName);

// Get Manifest

ZipEntry manifest = jf.getEntry(“META-INF/MANIFEST.MF”);

// Get Manifest date time

long manifestTime = manifest.getTime();

Date date = new Date(manifestTime );

DateFormat formatter = new SimpleDateFormat(“YYYY-MM-dd HH:mm:ss:SSS”);

String dateFormatted = formatter.format(date);            

log.info(“Executing Jar :” + jarFileName + ” with modified date: “ + dateFormatted);

%d bloggers like this: