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