ClassFileTransformer被ClassLoader調用。從你鏈接的文章,變壓器的稍加修飾,看起來像這樣:
public byte[] transform(ClassLoader loader, String className,
Class redefiningClass, ProtectionDomain domain, byte[] bytes)
throws IllegalClassFormatException {
new RuntimeException("Transformer to Transform Class: " + className)
.printStackTrace(System.out);
return bytes;
}
產生這樣的輸出:
java.lang.RuntimeException: Transformer to Transform Class: MyMain
at com.javalobby.tnt.instrument.SimpleTransformer.transform(SimpleTransformer.java:14)
at sun.instrument.TransformerManager.transform(Unknown Source)
at sun.instrument.InstrumentationImpl.transform(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
很好,謝謝。非常聰明的方式來找出,順便說一句:)。感謝您的嘗試! – Alix 2010-06-18 16:02:34