Call advice before main method when the aspect is a library component

455 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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.