Try adding this line :
ClassPool cp = ClassPool.getDefault(); pool.insertClassPath(new ClassClassPath(this.getClass()));
Have a look on this page http://www.csg.is.titech.ac.jp/~chiba/javassist/tutorial/tutorial.html
You were correct. It works. Thanks a lot!.
But I have discovered that the CDI approach is not valid for me because i am trying to process some JPA entities that seem to be loaded before by JPA/Hibernate so when i try to modify them it's to late: they are present on the classloader.
So i have taken the other way: i have written a JBoss extension with a DeploymentUnitProcessor and it seems to work fine, except that again i have no idea of how to get the classpath from the DeploymentPhaseContext. I can get the classloader like this:
but i don't know what's the next step.
Finally, i have some doubts about how it will perform taking in account that hibernate is also doing some "magic" on this clases.
Depending on what goal you are trying to achieve (could you explain a bit more ?) :
I would try to forget the byte code manipulation and go ahead with interceptors (in your CDI extension)
Or continue in bytecode manipulation direction and wrap the annotation type to return the modified bytecode.
To do so, overrid the getJavaClass() method (see Wrapping an AnnotatedType in http://docs.jboss.org/weld/reference/latest/en-US/html/extend.html#d0e5057)