I've been trying to call an advice before the main method of a program. Here is my aspect:
public final aspect MainProcessor {
pointcut mainMethod():
execution(public static void main(String[]));
before() : mainMethod(){
System.out.println(thisJoinPointStaticPart);
}
}
The main method which I'm trying to get is in another project, which is using my aspect project as a library. The main method is as simple as:
public static void main(String[] args) {
System.out.println("Main here");
}
This would work like a charm if it was in the same project as the aspect. However, in this case, it's only printing out "Main here" in the console. What can I do?
I just solved the problem. As I'm using Eclipse, instead of linking the library by adding it to the Java Build Path (Right click on the project -> Properties -> Java Build Path), I should have added it to the AspectJ Build (Right click on the project -> Properties -> AspectJ Build).
Hope this helps someone else.