[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Load time weaving problem
|
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!");
}
}