简体   繁体   English

Java:如何在JVM加载类时拦截类

[英]Java: How to intercept classes as they are being loaded by the JVM

In my program I want to intercept classes as they are being loaded by their ClassLoader and do some stuff with them eg. 在我的程序中,我想拦截类,因为它们被ClassLoader加载并用它们做一些事情,例如。 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? 我应该覆盖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. 问题在于,在大多数情况下,父ClassLoader可以加载类,因此我将无法获得所有类。 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. 关于这个网站上的一些问题我已经看到了Instrumentation被提及,但我不知道这是否与我的问题有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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