After a lot I found that the following is the code that works for me:
| ClassFile classFile = newProxyClass.getClassFile();
| ConstPool constantPool = classFile.getConstPool();
| AnnotationsAttribute attr = new AnnotationsAttribute(constantPool,
AnnotationsAttribute.visibleTag);
| javassist.bytecode.annotation.Annotation a = new
javassist.bytecode.annotation.Annotation(this.annotationClassName, constantPool);
| attr.setAnnotation(a);
| classFile.addAttribute(attr);
| classFile.setVersionToJava5();
|
|
| ByteArrayOutputStream bos = new ByteArrayOutputStream();
| DataOutputStream os = new DataOutputStream( bos );
| classFile.write( os );
| os.close();
|
| // all done
| return bos.toByteArray();
|
the above produces the byte code for a class with the added annotation.
Thanks,
Luca
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4140550#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...