The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

vicki (2) [Avatar] Offline
#1
I am trying to obtain an instrumented version of tjp.Demo class that AspectJ releases along with its libraries and compiler. Nothing works. I make different series of steps - but the result is: compiler does not give any errors, but when I run Demo after it supposedly had been instrumented - the output is the same as if it was not instrumented.
The steps I do:
1)javac tjp/Demo.java
2)ajc GetInfo.java //this is the aspect defined for Demo class
3)jar -cvf demo.jar tjp/Demo.class
4)jar -cvf demoaspect.jar tjp/GetInfo.class
5) ajc -inpath demo.jar -aspectpath demoaspect.jar -outjar aspecteddemo.jar

After this I unjar aspecteddemo.jar that is supposed to contain instrumented Demo, run tjp.Demo - and get the same result as when I ran it before doing all the instrumentation. Please, let me know what I am doing wrong. aspectjrt.jar is in my classpath.
Thanks a lot.
Vicki
ramnivas (171) [Avatar] Offline
#2
Re: AJC compiler does not instrument for me! Help!
Try the following:

1. ajc tjp/Demo.java GetInfo.java
2. java tjp.Demo

The problem is you need to compile all the sources together (there are other ways, but compiling sources together is the simplest).

-Ramnivas
vicki (2) [Avatar] Offline
#3
Re: AJC compiler does not instrument for me! Help!
Ramnivas, thanks a lot for the response. The thing is that I don't have the source of the target class and don't need it. My objective is to instrument binary, and not the source. I believe, that first version of aspectj did only the source instrumentation, but the new one does binary. Anyway, I found a solution to it by weaving the binary of a target class and the source of the aspect. What I did was:
ajc -injars<jar with target binary> -argfile<in our case the argfile contains this line: "GetInfo.java" - the source of an aspect> -outjar<location of output>.
This produced instrumented target class (Demo.class)
Thanks!
Vicki