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

There are 3 paths to think about with AspectJ when binary weaving:

Regular CLASSPATH - this is solely used to resolve type references.
Aspects are not discovered on it and classes on it are not woven into.

ASPECTPATH - this is actively searched for aspects.  The classes on
aspectpath are not woven into.

INPATH - this is actively searched for aspects *and* the classes on it
are woven into.

If you have just one jar and it contains your aspects, just use
inpath.  Here is an example:

--- A.java ---
import org.aspectj.lang.annotation.*;
@Aspect
public class A  {
  @Before("staticinitialization(!A)")
  public void beforeAdvice() {System.out.println("advice");}
}
--- C.java
public class C {
  public static void main(String []argv) {}
}
---

javac A.java -d out
javac C.java -d out
cd out
jar -cvMf stuff.jar *.class

ajc -inpath stuff.jar -outjar wovenstuff.jar -showWeaveInfo
Join point 'staticinitialization(void C.<clinit>())' in Type 'C'
(C.java) advised by before advice from 'A' (stuff.jar!A.class(from
A.java))

java -classpath "stuff.jar:<pathto>/aspectjrt.jar" C
this prints nothing

java -classpath "wovenstuff.jar:<pathto>/aspectjrt.jar" C
this prints:
advice

cheers,
Andy

On 9 May 2012 09:00, Jean Andre <Jean.Andre@xxxxxxxxxx> wrote:
> Thank you very much for your answer - A last question, is it necessary to
> have 2 separated and distincts  files for binary weaving, because as you
> have seen with the Worbench, the aspectJ classes and the source code are
> into the same project (WAR) and ultimely inside the same EAR.  So in our
> case it would be :
> ajc -aspectpath workbench.jar -inpath workbench.jar -outjar workbench2.jar
>
> Thank you in advance - JA
>
>
>
>
> De :        Andy Clement <andrew.clement@xxxxxxxxx>
> A :        aspectj-users@xxxxxxxxxxx
> Date :        2012-05-08 20:52
> Objet :        Re: [aspectj-users] Differences and impacts between .aj
> classes vs Java class with AspectJ annotation
> Envoyé par :        aspectj-users-bounces@xxxxxxxxxxx
> ________________________________
>
>
>
> 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
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top