Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Differences and impacts between .aj classes vs Java class with AspectJ annotation

Hi,

The only docs we really have are more on how-to-use-it rather than the
trade offs:

http://www.eclipse.org/aspectj/doc/released/adk15notebook/ataspectj.html

The two styles are called code-style (using the real AspectJ keywords)
and annotation-style (using the annotations).

> When we use @annotations, do we need to compile with the AspectJ compiler ?
> or the Javac compiler call the AspectJ compiler ?

When you use the annotation style, the code remains 'pure java' and so
you can build it with javac.  However, this does not cause the weaver
to be invoked, so the aspects are only built they are not
applied/woven.  The AspectJ weaver is a bytecode based weaver.
Regardless of which style you use (code or annotation), they will be
compiled to binary form before the weaver applies them.  So,
basically, I'm saying that choosing annotation style still needs the
weaver to be run at some point, and there are two options:

- after running javac to build the source, do a binary weave with the
AspectJ compiler:
ajc -aspectpath compiledAspects.jar -inpath codeToBeWoven.jar -outjar
wovenCode.jar

- use loadtime weaving, the weaver will run as the code is loaded and
the aspects will be woven into their targets.

> When a project is compile with the aspectJ compiler, do we need a runtime ?
> and by Annotation? It seems that using annotation means Load-time weaving
> and it requires 2 jars (aspectJ runtime and the weaver). It that true ?

For either style the final woven code will have dependencies on
aspectjrt.jar - this small jar contains the runtime dependencies (like
the implementation of 'thisJoinPoint').

And yes, for loadtime weaving, you will initially need the weaver
itself, which is aspectjweaver.jar, and that can be run as a
javaagent.

Andy


Back to the top