Thanks Ron, Alex and Andy for the prompt reply.
Andy weaving works fine if I use ajc. Using javaagent to get the aspect to weave-able state is not working as suggested. It still throws NoSuchMethodError. Meantime I will address the problem by using ajc at compile time and do LTW.
I would like to put forward the following to your notice. I may be greedy, but just as a user I would like - not to disturb either development environment or the runtime environment. To my knowledge it looks like core functionality which is weaving the aspect to the target class is achievable by using WeavingURLClassLoader, but getting aspect to a weave-able state requires either ajc
or javaagent.
Instead can AspectJ define an interface as follows:
public interface LTWAspect {
/* Need more documentation on what this method is expected to return*/
public Class aspectOf();
public .. hasAspect();
}
Any @Aspect can implement this interface and thus we can avoid ajc or inclusion of javaagent.
Being said this I admit I am per-mature aspectj user and please correct me if I am wrong.
Thanks
Gokul
From: Alexander Kriegisch <Alexander@xxxxxxxxxxxxxx>
To:
"aspectj-users@xxxxxxxxxxx" <aspectj-users@xxxxxxxxxxx>
Sent: Tuesday, 16 April 2013 9:14 PM
Subject: Re: [aspectj-users] LTW: Are there any posibilities to avoid using ajc and overcome NoSuchMethodError
As usual, Andy's answer is much smarter than mine. For them alone it makes sense to be on this list. Just saying... Compliments and thanks, you are one of my personal rock stars. :-)
Alexander Kriegisch
Actually the aspects do not need to be compiled with AspectJ. The aspects can be compiled with javac. *But* before they are usable they must be 'finished off' by ajc, but that can be done at loadtime. Here is my example:
// Code.java
public class Code {
public static void main(String []argv) {
new Code().m();
}
public void m() {}
}
// Doit.java
import org.aspectj.lang.annotation.*;
@Aspect
public class Doit {
@Around("execution(* m(..))")
public void advice() {
System.out.println("advice running");
}
}
// META-INF/aop-ajc.xml
<aspectj>
<aspects>
<!-- declare existing aspects to the weaver -->
<aspect name="Doit"/>
</aspects>
<weaver options="-showWeaveInfo">
<include within="*"/>
</weaver>
</aspectj>
====
> javac Doit.java Code.java
> java -javaagent:../lib/aspectjweaver.jar Code
[AppClassLoader@1ef6a746] weaveinfo Join point 'method-execution(void Code.m())' in Type 'Code' (Code.java:6) advised by around advice from 'Doit' (Doit.java)
advice running
The aspect should get 'finished off' (and the necessary aspectOf() and hasAspect() added) by the weaver just before it gets used. That doesn't seem to be happening with your setup - does it work for you with the agent?
On a quick look I think the problem might be that the WeavingURLClassLoader path into the system doesn't have a concept of unfinished aspects. You could try additionally including the aspect library in the classURLs list? That might be enough to remind it that it needs to finish it off.
cheers
Andy
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxxhttps://dev.eclipse.org/mailman/listinfo/aspectj-users