javassist.CannotCompileException: [source error] TryTest(com.asp.eb.TestPacket) not found in java.lang.Object
代码是这样的:
ClassPool pool = ClassPool.getDefault();
pool.insertClassPath(new ClassClassPath(clazz));
CtClass oldClass = pool.get(clazz.getName());
CtClass ct = pool.makeClass(new StringBuffer().append(oldClass.getName()).append("$Proxy").toString());
CtClass superCt = pool.get(HttpPacketHandler.class.getName());
ct.addInterface(superCt);
StringBuffer sb = new StringBuffer("public void handle (com.asp.eb.TestPacket packet)throws Exception{");
sb.append("int code = $1.getPacketId();");
sb.append("switch(code){");
Iterator ite =opMethods.entrySet().iterator();
while(ite.hasNext()){
Map.Entry entry = (Map.Entry)ite.next();
sb.append("case ").append(entry.getKey()).append(":");
sb.append("super.").append((String)entry.getValue()).append("($$);");
sb.append("break;");
opcodes.add(((Integer)entry.getKey()).intValue());
}
sb.append("}");
sb.append("}");
System.out.println("----------------------------------------");
System.out.println(sb.toString());
System.out.println("----------------------------------------");
CtMethod method = CtMethod.make(sb.toString(),ct);
不知道你这个问题是否已经解决, 如果还没有解决的话: