Search code examples
javahotswap

How to detect Hotswap


Is there any way to detect when classes have changed during run-time with Hotswap?

I have a class that generates data, which I store for later use. I can trigger the data regeneration manually after Hotswap has occurred, but I would like to automate this. I'm looking for any solution that would allow me to detect when any of the classes have changed so that the data could be regenerated on the fly automatically. I would also like to detect which classes were changed, since I have multiple classes generating different data and it's overhead to regenerate all of them.


Solution

  • You can use java agents to monitor any changes in byte code:

    API doc: http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/ClassFileTransformer.html

    Example:

    http://www.informit.com/guides/content.aspx?g=java&seqNum=589