简体   繁体   中英

Java - Class Loading - Last Modified Time

Does Java have the ability to tell the last time a class was modified when loading it? These classes may or may not be bundled in a .zip. Is there a generic way to do this?

There is no generic way to do this. you can however, get the url from which a class was loaded using class.getProtectionDomain().getCodeSource().getLocation() (note, some of those methods can return null, be sure to read the javadocs). you could then use the url to get either the modified time of the jar (or the entry inside the jar if that was included), or the class file itself if it is a standalone file (if it's a remote url, you may be able to use some http headers to get a last modified time as well)..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM