Hi, I am not very comfortable in Eclipse so this might be a simple question.
I made two projects, one is an AspectJ project, the other a regular Java project.
In the regular Java project I have a method main, that just writes hello world to stdout.
In the AspectJ project I have defined an aspect that cuts into main with a before advice that prints out "Hello from AspectJ". I've tested this aspect, and it works on any main methods inside the AJ project.
Now I have added the Java project to the InPath, so the advice gets woven into that too. I enabled the information messages and it reports that it has successfully woven my advice.
Now when I run the Java project it does not say "Hello from AspectJ", I take it this is because it runs the non-woven files.
My question is: How do I run the woven version of the Java project? I see in my terminal that it is in bin/ of the AspectJ project, but I don't know how I would run it using the right classpath and such.
1. You are currently using the in path. Using in path will re-weave the binary files of the Java project into your AJ project (unless you provide a specific new location (ie- the in path out folder)). If you want to continue doing so, you will need to add these rewoven jars as a class file folder and run the main method from there (instead of the original main method). This is a bit complex if you are not familiar with Eclipse, so you should try #2.
2. Add the AJ project to the Aspect path of your Java project instead of using in paht/ You must convert your Java project into an AJ project (you do not need to change the code at all, just need to add the AJ nature, use the AJ compiler, and include the AspectJ rt jar at runtime, all this will be done automatically if you convert to an AJ project). When you do this, you can just run the main method of your original class. This is because the aspect path will include all aspects from the other project for weaving.
Hi thanks for your reaction and your hard work on AspectJ
I managed to get possibility 1 working. I used the Eclipse click-through run configuration tool to launch the class, but it generated a wrong qualified name for the class which was why I thought that didn't work.
I noticed it prefixed 'main.' before my qualified name, removed that and it worked.