I want to add "insertBefore" to the JDK 5 base class method. For some reason, it does not work. Here is a sample code:
ClassPool pool = ClassPool.getDefault(); CtClass ctClass = pool.get("com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter"); CtMethod ctMethod = ctClass.getDeclaredMethods()[0]; ctMethod.insertBefore("System.out.println(\"WORKED\");"); ctClass.toClass();
com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter comes bundled with the JDK, inside rt.jar. After the above snippet, I run some code that causes the XSMessageFormatter class to run, but my pasted code never runs. I can only make it work in my own classes. This code works like a simple standalone application.
Any ideas?
source share