0

I am developing a library and I need to add extra codes to some of my methods of my objects at run time. there are two points here. first of all, the program I wanted to add extra code, is written before by some body else, and I don't wanted to edit it. second, my work is very similar to adding aspect before calling a method.

After searching and reading on in internet, I found out many frameworks like aspectj, ASPECTWERKZ and etc. that could do this job, but for example the problem with aspectj(when using in spring context) is that it doesn't provide you any API to do your weaving at runtime. I also found out there are some libraries like ASM and javassist and etc. but they are so general and hard to learn, and my job is more likely to aspects.

So what do you suggest? is there any good library out there? Am I wrong about above libraries i mentioned earlier? Please Help!

saman
  • 199
  • 4
  • 17

1 Answers1

0

With AspectJ you can apply your aspects when classes are loaded at runtime. See Load-Time Weaving documentation. Alternatively, you don't have to change your old code and can apply aspects at compile time.

Eugene Kuleshov
  • 31,461
  • 5
  • 66
  • 67
  • As it is said, it can do weaving at run-time, not load time. the point here is that I wanted to add aspect after loading classes by class loader. – saman Jun 15 '12 at 05:20
  • AspectJ LTW does exactly just that, instrumenting code before it is loaded by class loader. If you want to instrument code that is already loaded, it is entirely different story, but your question is unclear on that. – Eugene Kuleshov Jun 18 '12 at 20:22
  • 1
    Not possible to do what exactly? Add code before classes are loaded or after or you want to add it before calling some code and then remove it? Please edit your question with exact details. – Eugene Kuleshov Jun 19 '12 at 13:46