[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Please help getting started - load time weaving (LTW) doesn't work
|
-------- Original-Nachricht --------
> Datum: Wed, 24 Oct 2007 22:02:49 -0500
> Von: Dean Wampler <dean@xxxxxxxxxxxxxxxxxxxxx>
> An: aspectj-users@xxxxxxxxxxx
> Betreff: Re: [aspectj-users] Please help getting started - load time weaving (LTW) doesn\'t work
> Based on a quick reading, here are a couple of suggestions:
>
> 1) Try compiling everything together with ajc, so you don't mess with
> configuring the aspect, weaving, etc. Does it work then? If so, there
> is something wrong in the LTW configuration that isn't apparent to me.
Quoting myself (from my "Addendum"):
"If the to-be-weaved classes (Test, MyEntity) are available to the AspectJ compiler, it seems to work;"
so yes, it does work then, but I need LTW to work
> 2) You probably don't want around advice. Without a "proceed()" call
> in the advice, the original join point is never executed. Either
> before or after advice is probably all you want here. Well, except
> for how you're using the advice for the "getField" pointcut.
Well, that's exactly what I want... as said, I only tried with the method pointcut/advice b/c the "getField" one didn't work at all and I wanted to see if a "simpler one" would work (maybe I got the pointcut wrong etc.) - as said, it doesn't work with LTW, only when compiling everything together with ajc... which is not an option.
>
> 3) Are your other classes in the classpath seen by java when you
> start the app? (It sounds like the answer is "yes", based on the
> weaver output.)
Yep, definitely, they see each other and everything works... except AspectJ LTW.
I chose AspectJ b/c it seems to be much more popular but I must say, I needed only two hours or so to get a working JBossAOP field interceptor.
Still, if possible, I'd like to use AspectJ but I'd need to get LTW working :-(
>
> dean
>
Thanks for trying to help me & kind regards,
Messi
> On Oct 24, 2007, at 3:57 PM, Bernhard Messerer wrote:
>
> > Hi all,
> >
> > My problem is that AspectJ doesn't weave my aspect, so I've reduced it
> > to test - still no weaving.
> > I have this aspect:
> >
> > public privileged aspect MyAspect {
> > pointcut testMethod() : execution(* *.*(..));
> > pointcut getField() : get(* (@Entity *).*);
> >
> > Object around() : testMethod() {
> > System.err.println("JOINPOINT testMethod() called");
> > return "ASPECTVALUE";
> > }
> > Object around(): getField() {
> > System.err.println("getField() called");
> > return "ASPECTVALUE";
> > }
> > }
> >
> > which should, as I understand it, weave to all methods and these
> > classes:
> > MyEntity.java
> >
> > @Entity
> > public class MyEntity {
> > public String ajField="startValue";
> >
> > public String testGet() { return ajField; }
> > public void testSet(String val) { ajField=val; }
> >
> > public String ajMethod() {
> > System.out.println("public ajMethod() called");
> > return "ValueFromAJMethod";
> > }
> >
> > public Object indirectM2() {
> > return ajMethod2();
> > }
> >
> > private Object ajMethod2() {
> > System.out.println("private ajMethod2() called");
> > return "ValueFromAJMethod";
> >
> > }
> > }
> >
> > and Test.java:
> > public class Test {
> > public static void main(String[] args) {
> > Test t=new Test();
> > }
> > public Test() {
> > Object result="OriginalValue";
> > MyEntity e=new MyEntity();
> > System.out.println("Calling ajMethod()");
> > result=e.ajMethod();
> > System.out.println("ajMethod() returned '"+result+"'");
> > System.out.println("Calling ajMethod2() via indirectM2()");
> > result=e.indirectM2();
> > System.out.println("ajMethod2() via indirectM2() returned
> > '"+result+"'");
> > System.out.println("Calling testGet()");
> > result=e.testGet();
> > System.out.println("testGet() returned '"+result+"'");
> > System.out.println("Calling testSet(...)");
> > e.testSet("newValue");
> > System.out.println("Calling testGet()");
> > result=e.testGet();
> > System.out.println("testGet() returned '"+result+"'");
> > System.out.println("Exiting");
> > }
> > }
> >
> > and this META-INF/aop.xml:
> > <aspectj>
> > <aspects>
> > <aspect name="MyAspect"/>
> > <!-- no includes/excludes means "use all (declared)
> > aspects" -->
> > </aspects>
> >
> > <weaver options="-verbose -debug -showWeaveInfo">
> > <!-- no includes/excludes means "weave to all classes (visible
> > to the weaver)" -->
> > </weaver>
> >
> > </aspectj>
> >
> > I start the program with -javaagent:path/to/aspectjweaver.jar and
> > indeed, get (among others) these log messages:
> >
> > [AppClassLoader@1f12c4e] info AspectJ Weaver Version 1.5.3 built on
> > Wednesday Nov 22, 2006 at 11:18:15 GMT
> > [AppClassLoader@1f12c4e] info register classloader
> > sun.misc.Launcher$AppClassLoader@1f12c4e
> > [AppClassLoader@1f12c4e] info using configuration
> > file:/[...]myApp.jar!/META-INF/aop.xml
> > [AppClassLoader@1f12c4e] info register aspect MyAspect
> >
> > and even:
> > [AppClassLoader@1f12c4e] debug weaving 'Test'
> > [AppClassLoader@1f12c4e] debug weaving 'MyEntity'
> >
> > yet no aspect seems to get executed (what I really want to do is
> > intercept field-access but tried with the method to get at least
> > _something_ weaved/running), no method prints anything or even returns
> > one of the values of my aspect.
> > I build with ant & iajc task and use JDK6u2 on WinXP SP2; I also tried
> > to run with the aj5 script with same results.
> > Do I have something wrong with my pointcuts? And why does AspectJ tell
> > me that it is weaving (among others) the classes I want it to?
> > Can anybody please help me to at least get started in my environment?
> > (Please note that I removed package-names for shortening and b/c
> > I'm not
> > sure whether I may publish them, but they're correct, I'm sure).
> >
> > Addendum:
> > I read (in the reply to "AspectJ compilation question") that "Yes,
> > AspectJ supports weaving inpath classes and jars. This is available
> > through the ajc command line interface, ant tools, and Eclipse
> > plugin AJDT."
> >
> > The classes Test and MyEntity are not available to the aspectj-
> > compiler (iajc) at compile time and I get the warning "advice
> > defined in MyAspect has not been applied [Xlint:adviceDidNotMatch]".
> > Does that mean that all classes to be woven, even with the load-
> > time-weaver, must be kind of "prepared" by the AspectJ compiler? If
> > yes, is there any way around this, as it would make AspectJ useless
> > for my case (thus I cannot imagine that this is required).
> > If the to-be-weaved classes (Test, MyEntity) are available to the
> > AspectJ compiler, it seems to work; the result is also different
> > when using JDK5 instead of JDK6, I then get some exceptions -
> > Searching in Google, it seems AspectJ 1.5.3 supports (or at least
> > "works on") JDK6, even improving performance quite a bit.
> >
> > So, can anybody help? Of course, I'll give further info if needed.
> >
> > Thanks in advance & kind regards,
> >
> > Messi
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
> Dean Wampler, Ph.D.
> dean at objectmentor.com
> http://www.objectmentor.com
> See also:
> http://www.aspectprogramming.com AOP advocacy site
> http://aquarium.rubyforge.org AOP for Ruby
> http://www.contract4j.org Design by Contract for Java5
>
> I want my tombstone to say:
> Unknown Application Error in Dean Wampler.exe.
> Application Terminated.
> [Okay] [Cancel]
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser