I m drawing upon an answer from a similar question.
It seems you can get location of jar file by following :
public class ClassFileHelper {
public static URL getClassURL(Class<?> clazz) {
return clazz.getResource('/' + clazz.getName().replace('.', '/') + ".class");
}
public static String getJARFromURL(URL url) {
if (!url.getProtocol().equals("jar"))
return null;
String fileName = url.getFile();
fileName = fileName.substring(0, fileName.lastIndexOf('!'));
fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
return fileName;
}
}
Class clazz = MyClass.class;
URL classURL = ClassFileHelper.getClassURL(clazz);
String jarFile = ClassFileHelper.getJARFromURL(classURL));
Then to get the signed timestamp , I am again copying some other answer from a question here - excuse me for my impunity!
File f = new File( jarFile );
if ( f.exists() ) ->
Execute the command jarsigner -verify -verbose -certs myjar.jar by using Runtime.exec(...) - make sure the right location of jarsigner was passed to arguments.
parse the output which is of the form [entry was signed on 8/2/13 3:48 PM] to get the time stamp.
Another option is to use keytool in JRE :
keytool -printcert -jarfile myApp.jar