Re: Compile Date



On Wed, 30 Jul 2008 16:01:12 -0400, Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx> wrote:

Is the compile date of a class embedded in the class file somewhere? I
could see not putting it in to avoid false deltas when the code did
not really change.

It there a method to find out when a class was most recently compiled?

I suppose it could be handled with a script that generates a little
class containing today's date that gets freshly recompiled each day,
but that really just tells you when the jar was built.



You should be able to get the lastmodified information for the .class file from the filesystem. A jar utility should preserve the modification date for each file in the archive. So:

public static Date getCompileTime(Class<?> cls) throws IOException
{
ClassLoader loader=cls.getClassLoader();
String filename=cls.getName().replace('.', '/')+".class";
URL resource=(loader!=null) ?
loader.getResource(filename) :
ClassLoader.getSystemResource(filename);
URLConnection connection=resource.openConnection();
long time=connection.getLastModified();
return (time!=0L) ? new Date(time) : null;
}

I won't swear that will work in all cases, but perhaps it will point you in the right direction?

HTH,

-Zig
.