I am trying to choose between AspectJ and Javassist as testing tools in my company. Javassist seems to me more straightforward, and I lean towards it, but there are some utility functionality that is harder to implement in Javassist. For instance, I cannot use System.out.println for printing out tested method's arguments or local variables because the instrumented classes are running in appserver container or because of some other reason... I need to user FileWriter to create test logs. I was trying to create logging method with CtNewMethod.make(..), and my instrumentor class compiles fine, but when I run it against class to be instrumented I get
Exception in thread "main" javassist.CannotCompileException: [source error] no such class: FileWriter
Caused by: compile error: no such class: FileWriter
Could anyone please point me into the direction of where I can find a code snippet showing how to do it right?
Thanks a lot!
See the CMP documentation and load-groups.