I found out what goes wrong and solve the problem now. It looks like the problem is caused by losing aop-ajc.xml as referred to (thanks for help!). Also it should be in the META-INF folder.
I appreciate all your help. Thank you. : ) The steps to get it run: 1.) ajc -outjar ./lib/character.jar character/Person.java 2.) ajc -outjar ./lib/inspect.jar -outxml observer/Inspector.aj (outxml will include aop-ajc.xml in outjar file. This is where the thing goes wrong previously.) To examine if it is load time weaving, to run plain java class file first; then to run with weaving class. 3.) aj -javaagent:/home/neo/app/aspectj1.6/lib/aspectjweaver.jar -classpath "./:./lib/character.jar" character.Person or java -classpath "./:./lib/character.jar" character.Person if it is compile-time weaving, then directly executing plain java file will cause NoAspectBoundException exception (If I am correct). Exception in thread "main" java.lang.NoClassDefFoundError: org/aspectj/lang/NoAspectBoundException at character.Person.speak(Person.java:18) at character.Person.main(Person.java:22) Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.NoAspectBoundException at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) ... 2 more 4.) aj -javaagent:/home/neo/app/aspectj1.6/lib/aspectjweaver.jar -classpath "./:./lib/inspect.jar:./lib/character.jar" character.Person The source: package character; public class Person{ private String name; public Person(String name){ this.name = name; } public String getName(){ return this.name; } public void setName(String name){ this.name = name; } public void speak(String sentence){ System.out.println(this.name+" say : '"+sentence+"'"); } public static void main(String args[]){ new Person("Jason").speak("This is a book!"); } } package observer; public aspect Inspector{ pointcut observer(): execution(* character.Person.speak(..)); // && this(Person); before(): observer(){ System.out.println("before speaking something, thinking ..."); } } --- On Sat, 6/9/08, Ron DiFrango <[EMAIL PROTECTED]> wrote: > From: Ron DiFrango <[EMAIL PROTECTED]> > Subject: Re: [aspectj-users] Load time weaving problem > To: [EMAIL PROTECTED] > Cc: aspectj-users@eclipse.org > Date: Saturday, 6 September, 2008, 7:23 PM > The way I understand it that enabling the agent is not > enough, you > also need the aop.xml file as well. > > Ron DiFrango > > On Sep 6, 2008, at 3:19 PM, Neo Anderson wrote: > > > I specify the agent on the step 4 where there includes > '-javaagent:/ > > path/to/aspectj1.6/lib/aspectjweaver.jar' as > stated in the > > configuration page., unless I misunderstand its > meaning (.If so, > > please tell me the right format.) > > > > Thank you very much, > > > > > > --- On Sat, 6/9/08, Ron DiFrango > <[EMAIL PROTECTED]> > > wrote: > > > > > From: Ron DiFrango > <[EMAIL PROTECTED]> > > > Subject: RE: [aspectj-users] Load time weaving > problem > > > To: [EMAIL PROTECTED], > aspectj-users@eclipse.org, > > aspectj-users@eclipse.org > > > Date: Saturday, 6 September, 2008, 6:36 PM > > > I am not LTW expert, but do you have an aop.xml > file defined > > > and on the classpath like the documentation says > here: > > > > > > > http://www.eclipse.org/aspectj/doc/released/devguide/ltw- > > configuration.html > > > > > > If so, maybe supplying that as well would help. > > > > > > Ron DiFrango > > > Manager / Architect > > > Cap Tech Ventures, Inc > (http://www.captechventures.com) > > > Blog (http://www.captech-soa.blogspot.com) > > > Cell: 804-855-9196 > > > Work: 804-545-8742 > > > > > > > > > > > > -----Original Message----- > > > From: [EMAIL PROTECTED] on behalf > of Neo > > > Anderson > > > Sent: Sat 9/6/2008 1:58 PM > > > To: aspectj-users@eclipse.org > > > Subject: Re: [aspectj-users] Load time weaving > problem > > > > > > I fix that problem, but I still can not run > load-time > > > weaving. There is no error, it only produces > result as there > > > is no weaving at all. > > > > > > The step to run the example is > > > > > > 1.) javac -classpath ./ character/Person.java > > > > > > 2.) ajc observer/Inspector.aj > > > > > > 3.) ajc -outjar ./lib/inspect.jar > observer/Inspector.aj > > > > > > warning at this step: > > > > > > Inspector.aj:4 [warning] no match for this type > name: > > > character.Person [Xlint:invalidAbsoluteTypeName] > > > pointcut observer(): execution(* > > > character.Person.speak(..)); // && > this(Person); > > > > ^^^^^^^^^^^^^^^^^^^^ > > > [Xlint:invalidAbsoluteTypeName] > > > > > > > > > 4.) export > > > > ASPECTPATH=./lib/inspect.jar:$ASPECTJ_HOME/lib/aspectjrt.jar > > > > > > 5.) aj > > > > -javaagent:/home/neo/app/aspectj1.6/lib/aspectjweaver.jar > > > -cp ./ character.Person > > > > > > what might go wrong? > > > > > > Thanks in advice, > > > > > > The source now is as below: > > > > > > package character; > > > > > > public class Person{ > > > private String name; > > > > > > public Person(String name){ > > > this.name = name; > > > } > > > > > > public String getName(){ > > > return this.name; > > > } > > > public void setName(String name){ > > > this.name = name; > > > } > > > > > > public void speak(String sentence){ > > > > System.out.println(this.name+" say : > > > '"+sentence+"'"); > > > } > > > > > > public static void main(String args[]){ > > > new > > > Person("Jason").speak("This is a > > > book!"); > > > } > > > > > > } > > > > > > package observer; > > > > > > public aspect Inspector{ > > > pointcut observer(): execution(* > > > character.Person.speak(..)); // && > this(Person); > > > > > > before(): observer(){ > > > System.out.println("before > speaking > > > something, thinking ..."); > > > } > > > } > > > > > > > > > > > > --- On Sat, 6/9/08, Andrew Eisenberg > > > <[EMAIL PROTECTED]> wrote: > > > > > > > From: Andrew Eisenberg > <[EMAIL PROTECTED]> > > > > Subject: Re: [aspectj-users] Load time > weaving problem > > > > To: [EMAIL PROTECTED], > > > aspectj-users@eclipse.org > > > > Date: Saturday, 6 September, 2008, 4:48 PM > > > > When using LTW, the first step is to ensure > that your > > > > pointcuts are > > > > applying to the correct joinpoints. > Unfortunately, > > > AJDT > > > > doesn't help > > > > much with this. > > > > > > > > My suggestion to you is to turn off LTW and > try to get > > > the > > > > program > > > > working using standard compile time weaving. > > > You'll > > > > find that your > > > > pointcut isn't correct. > > > > > > > > If you can't figure it ask again and > I'll tell > > > you > > > > how to fix your pointcut. > > > > > > > > On Sat, Sep 6, 2008 at 7:41 AM, Neo Anderson > > > > <[EMAIL PROTECTED]> wrote: > > > > > I am learning to use load-time weaving > features > > > > provided by aspectj, but I can not get my > example > > > worked > > > > whilst running it. The problem is that the > load-time > > > > weaving seems not work. > > > > > > > > > > There are two classes named > character/Person.java > > > and > > > > observer/Inspector.aj (source is as listed ) > . > > > > > > > > > > The way how I compile it is > > > > > 1.) compile Person.java > > > > > javac -classpath ./ > character/Person.java > > > > > 2.) compile aspectj source > > > > > ajc -1.6 observer/Inspector.aj (This > step > > > issues > > > > warning which oreilly's aspectj cookbook > says it > > > is ok) > > > > > > > > > > [warning] no match for this type name: > Person > > > > [Xlint:invalidAbsoluteTypeName] > > > > > pointcut observer(): execution(* > speak(..)) > > > && > > > > this(Person); > > > > > > > > > > > > ^^^^ > > > > > [Xlint:invalidAbsoluteTypeName] > > > > > > > > > > > > > /home/neo/workspace/coding/aspectj/load-time-weaving/observer/ > > > Inspector.aj:6 > > > > [warning] advice defined in > observer.Inspector has not > > > been > > > > applied [Xlint:adviceDidNotMatch] > > > > > > > > > > 3.) produce outjar and export it in > ASPECTPATH > > > > > ajc -outjar lib/inspector.jar > > > observer/Inspector.aj > > > > > export ASPECTPATH=./lib/inspect.jar > > > > > > > > > > 4.) run example > > > > > aj > -javaagent:$ASPECTJ_HOME/lib/aspectjweaver.jar > > > -cp > > > > ./ character.Person > > > > > > > > > > > > > The result only shows "Jason speak > : This is > > > a > > > > book!" without weaving. > > > > > > > > > > What I expect is > > > > > stage before speaking something! > > > > > Jason speak : This is a book! > > > > > > > > > > Where did I do it wrong? > > > > > > > > > > My env: aspectj1.6/ open suse 11.0 > 64bit/kernel > > > > 2.6.25-1.1-default/ jdk1.6.x > > > > > > > > > > I appreciate any advice, > > > > > > > > > > Thank you very much > > > > > > > > > > The source is as below: > > > > > > > > > > package character; > > > > > > > > > > public class Person{ > > > > > private String name; > > > > > > > > > > public Person(String name){ > > > > > this.name = name; > > > > > } > > > > > > > > > > public String getName(){ > > > > > return this.name; > > > > > } > > > > > public void setName(String > name){ > > > > > this.name = name; > > > > > } > > > > > > > > > > public void speak(String > sentence){ > > > > > > > > System.out.println(this.name+" > > > > speak : "+sentence); > > > > > } > > > > > > > > > > public static void main(String > args[]){ > > > > > new > > > > Person("Jason").speak("This > is a > > > > book!"); > > > > > } > > > > > } > > > > > > > > > > package observer; > > > > > > > > > > public aspect Inspector{ > > > > > pointcut observer(): execution(* > > > speak(..)) > > > > && this(Person); > > > > > > > > > > before(): observer(){ > > > > > > System.out.println("stage > > > before > > > > speaking something!"); > > > > > } > > > > > } > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > aspectj-users mailing list > > > > > aspectj-users@eclipse.org > > > > > > > > > https://dev.eclipse.org/mailman/listinfo/aspectj-users > > > > > > > > > > > > > > > > > _______________________________________________ > > > aspectj-users mailing list > > > aspectj-users@eclipse.org > > > > https://dev.eclipse.org/mailman/listinfo/aspectj-users > > > > > > > > _______________________________________________ aspectj-users mailing list aspectj-users@eclipse.org https://dev.eclipse.org/mailman/listinfo/aspectj-users