compile timestamp : Java Glossary
- compile timestamp
The date and time a class was compiled is not embedded in the class file. This avoids false deltas when you recompile to the exact
same code as previously. So how could you find out when a class was last compiled?
Here are some techniques depending on what you mean. Do you want the time the class
file last changed, or the last time you did a build, that may or may not have
modified that particular class file.
- Write a little utility to embed a static final
constant string in each Java source file (or in a common class) with current date
and time just prior to a major compile.
- Checking into a version control system often stamps a time stamp comment into
the source, but it is not be easily accessible.
- Write a program that creates a little file with a line for each class of a
project with its name and modification dates and include it in the jar as a
- Using Class.getProtectionDomain.
getCodeSource, find the jar the classloader used and
peek inside the jar file at run time and look at the member timestamps.
- Using Classloader.getResource to get at the class file member in the jar.
- Use the annotations feature to embed the timestamp in the class file.
Presumably you hack the class file format and patch in the timestamps. There may
exist easier ways of implementing that approach.