title: How to use the Java Instrumentation API to reload classes when they change on the the file system?
body: <ul>
  <li>I don't want to use the URL Classloader to load classes. </li>
  <li>I want to implement this myself.</li>
  <li>I don't want to use a solution like JRebel (although it's great).</li>
  </ul>
  
  <p>I've got prior experience of JavaAssist, bytecode generation, implementing javaagent class transformers etc. </p>
  
  <p>I would like to write a javaagent which hooks into the classloader or defines it's own system classloader. </p>
  
  <p>I'll store the class files in an in memory cache, and for particular files, periodically reload them from disk.</p>
  
  <p>I'd prefer to do this in a way which doesn't involve continuously polling the file system and manually invalidating specific classes. I'd much rather intercept class loading events.</p>
  
  <p>I last messed around with this stuff 4 years ago, and I'm sure, although my memory may deceive me that it was possible to do, but 8 hours of searching google doesn't present an obvious solution beyond building a patched JVM.</p>
  
  <p>Is this actually possible? </p>
  
  <p>I've created a stub implementation at <a href="https://github.com/packetops/poc_agent" rel="nofollow noreferrer">https://github.com/packetops/poc_agent</a> if anyone's interested in a simple example of javaagent use. </p>
  
  <h1>update</h1>
  
  <p>Just found this <a href="https://stackoverflow.com/questions/13498741/define-custom-system-classloader">post</a> - I may have been using the wrong approach, I'll investigate further. </p>