Environnement : Simple Java stand-alone application. AspectJ jar inside.
I’ve two projects. The first one, say ‘A’ contains a custom method scope annotation and an aspect who is in charge of doing some task when the method is called.
The annotation :
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AccessibleForRole {
String value() ;
}
The aspect :
public aspect AccessibleListener {
pointcut verifyRole():
(
call(@AccessibleForRole * *())
);
before() : verifyRole() { // do something
}
}
I’ve done a jar file with thoses annotations/aspects.
After that, I create a model class in project A. I annotate a method with my annotation, run the program and I see the aspect catching the event and working on.
public class Model {
@AccessibleForRole("admin")
public void addUserToApplication(){
System.out.println("in Model.addUserToApplication.");
}
}
It works fine….but….
If I create a second project, project ‘B’ using jar ‘A’, and I create new classes, with methods that I annotate (same a Model for example), it seems that nothing special occurs. Nothing is catched.
Is it possible to create, in the future, something that have to be catched with AspectJ from project A jar, without having to recompile ?
Thanks in advance,
Problem resolved.
Thanks to a Maven plugin : http://mojo.codehaus.org/aspectj-maven-plugin/libraryJars.html
I put :
And when building or running, code from project B is correctly intercepted by the aspect define in jarA.
I hope this will help.