[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[ews.eclipse.technology.aspectj] Load Time Weaving AspectJ 5
|
Hello,
I have problems when trying using LTW with ApectJ 5 with java 5.
1.First example I tried to run:
As the suggested in the Eclipse demo for LTW, I have Two projects:
***an aspect project Trace containing the simple following aspect :
package myPAck;
import org.aspectj.lang.annotation.*;
@Aspect
public class MyAspect {
@Pointcut ("execution(* *(..))")
void anyMathod(){}
@Before ("anyMathod()")
public void tracer(){
System.out.println("testing the LWT");
}
}
***a java project containing the simple following class:
package test;
public class Hello {
public void sayHello(){
System.out.println("Hello!");
}
public static void main(String[] args) {
Hello h= new Hello();
h.sayHello();
}
}
I've put the aspectJ jar and the aspectjweaver in the classpath, and
passed the option -javaagent:lib/aspectjweaver.jar to the JVM and tried
to run by following theses steps:
run... -> Load Time weaving -> new configuration -> (put the java project
and the class of main into ) -> (put the aspect project in the LWT
aspectPath ) -> run. The result is just the result of the main, so the
weaving has not been done.
2. My second example uses an aop.xml file.
Here is my project structure:
I have two pakcages : aop.aspectj0 containing the class main
package aop.aspectj0;
import aop.aspectj1.Machin;
public class MonMain {
public void a(){
System.out.println(" la méthode a() ");
}
public void b(){
System.out.println(" la méthode b() ");
}
public void c(){
System.out.println(" la méthode c() ");
}
public static void main(String[] args) {
Machin machin = new Machin();
machin.bidule();
MonMain mm = new MonMain();
mm.a();
mm.b();
mm.c();
}
}
the secon d package aop.aspectj1 containing the class:
package aop.aspectj1;
public class Machin {
public void bidule(){
System.out.println("bidule");
}
}
ans a third package containing two aspects:
package aop.aspectj.aspects;
import org.aspectj.lang.annotation.*;
import aop.aspectj0.MonMain;
@Aspect
public class TraceAp {
MonMain monmain;
@Pointcut("execution (* aop..*.*(..))")
void macoupe1(){}
@After("macoupe1()")
public void say() throws SecurityException, NoSuchMethodException{
System.out.println("aprèsla méthode");
}
}
And
package aop.aspectj.aspects;
import org.aspectj.lang.annotation.*;
import aop.aspectj0.MonMain;
@Aspect
public class TraceAp {
MonMain monmain;
@Pointcut("execution (* aop..*.*(..))")
void macoupe1(){}
@After("macoupe1()")
public void say() throws SecurityException, NoSuchMethodException{
System.out.println("aprèsla méthode");
}
}
And finally the aop.xml file put in the MATA-INF folder looks like:
<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>
<!-- declare existing aspects to the weaver -->
<aspect name="aop.aspectj.aspects.TraceAv"/>
<aspect name="aop.aspectj.aspects.TraceAp"/>
<exclude within="aop.aspectj.aspects.TraceAv"/>
</aspects>
<weaver options="-verbose -XlazyTjp">
<include within="aop.aspectj0.*"/>
<exclude within="aop.aspectj1.*"/>
</weaver>
</aspectj>
The result of runnning the application is weaving all aspects within all
classes which I don't hope to occur. Actually, in the aop.xml I'm supposed
to tell the weaver to not weave the TraceAv apsect and not weave within
the aop.aspect1 package classes.
I hope I'm clear enough talking about my examples and hope have some help
to run an aop application with LTW.
Ii 'll be useful for me too to have any complete example of using load
time weaving using aspectj5.
Thanks in advance.