You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Test.java 614B

12345678910111213141516
  1. import javassist.*;
  2. public class Test {
  3. public static void main(String[] args) throws Exception {
  4. ClassPool cp = ClassPool.getDefault();
  5. // ClassPool cp = new ClassPool();
  6. cp.insertClassPath("./target/test-classes");
  7. CtClass cc = cp.get("test4.JIRA207");
  8. // cc.getClassFile().setMajorVersion(javassist.bytecode.ClassFile.JAVA_4);
  9. CtMethod cm = cc.getDeclaredMethod("foo");
  10. cm.insertBefore("throw new Exception();");
  11. CtMethod cm2 = cc.getDeclaredMethod("run2");
  12. cm2.insertBefore("throw new Exception();");
  13. cc.writeFile();
  14. }
  15. }