6

In my program I want to intercept classes as they are being loaded by their ClassLoader and do some stuff with them eg. check for certain annotations etc. How do I do this?

I have already done a lot of research online but have not gotten my answer. Should I perhaps override ClassLoader? The problem with that is that the parent ClassLoader gets to load the class in most cases, so I won't be able to get ALL classes. On a couple questions on this site I've seen Instrumentation get mentioned, but I don't know if that is relevant to my problem.

1
  • How complex would ClassLoader-overriding be? Apr 17, 2012 at 22:29

1 Answer 1

1

You can use java agents to monitor this:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.