Skip to main content



      Home
Home » Language IDEs » AspectJ » HelloWorld with a twist
HelloWorld with a twist [message #45065] Sun, 19 December 2004 18:25 Go to next message
Eclipse UserFriend
Originally posted by: sekar.gopinathan.fhlbny.com

Hi,

I used the eclipse AJDT tutorial to create a HelloWorld application and it
worked great. I added one more advice in addition to the after() advice
and it goes something like
public aspect World {
pointcut greeting() : execution(* HelloWorld.sayHello(..));
before() : greeting() {
System.out.println("After Hello");
}
after() : greeting() {
System.out.println("After Hello");
}
}
and my HelloWorld is the same as the one in the tutorial except for the
output "Hello from HelloWorld" in sayHello() method.

Now I wanted to make the aspect a library that HelloWorld project can use.
So I created a HelloAspect project and moved the World.aj aspect into
that project. Both projects are Aspect projects. Now in the
HelloAspect project, I set the output variable in AspectJ properties to
hello.jar(as per the article by Adrian in one of the posts in
Aspectprogrammer.org.a very good one that) Also, in the HelloWorld
project, I set the AspectJ aspect path to hello.jar in the HelloAspect
project. I noticed that I could see the markers in my java editor
(although the tool tip showed the jar file ie., hello.jar). So now I
compiled and run the program once again I got the output as expected i.e.,
"Before Hello"
"Hello from HelloWorld"
"After Hello"

Once I got this I decided to remove the after() advice in the World.aj
and saved it and run the program once again to ensure that my changes to
the aspect reflect on my code. I got an error, like
After Hello
Hello from HelloWorld...
java.lang.NoSuchMethodError:
myPackage.World.ajc$after$myPackage_World$2$f69f5afa()V
at myPackage.HelloWorld.sayHello(HelloWorld.java:28)
at myPackage.HelloWorld.main(HelloWorld.java:22)
Exception in thread "main"
so I put that advice back in and removed the before() advice and did the
same again. Now I got the following error.
java.lang.NoSuchMethodError:
myPackage.World.ajc$after$myPackage_World$2$f69f5afa()V
at myPackage.HelloWorld.sayHello(HelloWorld.java:28)
at myPackage.HelloWorld.main(HelloWorld.java:22)
My initial guess was that the HelloWorld projet is not in the "inpath" of
HelloAspect project. So I put the HellWorld/bin directory in the "inpath"
of HelloAspect project. Right after I hit ok I got a problem in my task
list and it read something like
"class 'myPackage.HelloWorld' is already woven and has not been built with
-Xreweavable". That's how far I could go with this.
Does anyone know how to keep aspects as a library in one project and be
able to weave the changes in aspect to the code in another project? I
think I may be missing something here.
Any "advice" appreciated. My apologies if I am doing something really
stupid and annoying you all...:)

Signing off
lost():withing(aspects)...:)
Re: HelloWorld with a twist [message #45077 is a reply to message #45065] Sun, 19 December 2004 23:20 Go to previous message
Eclipse UserFriend
Originally posted by: sekar.gopinathan.fhlbny.com

I found that by cleaning all the projects, it recompiles and weaves the
aspect fine. After reading some of the threads here, I understand its a
bug.

Thanks
SG

Sekar Gopinathan wrote:

> Hi,

> I used the eclipse AJDT tutorial to create a HelloWorld application and it
> worked great. I added one more advice in addition to the after() advice
> and it goes something like
> public aspect World {
> pointcut greeting() : execution(* HelloWorld.sayHello(..));
> before() : greeting() {
> System.out.println("After Hello");
> }
> after() : greeting() {
> System.out.println("After Hello");
> }
> }
> and my HelloWorld is the same as the one in the tutorial except for the
> output "Hello from HelloWorld" in sayHello() method.

> Now I wanted to make the aspect a library that HelloWorld project can use.
> So I created a HelloAspect project and moved the World.aj aspect into
> that project. Both projects are Aspect projects. Now in the
> HelloAspect project, I set the output variable in AspectJ properties to
> hello.jar(as per the article by Adrian in one of the posts in
> Aspectprogrammer.org.a very good one that) Also, in the HelloWorld
> project, I set the AspectJ aspect path to hello.jar in the HelloAspect
> project. I noticed that I could see the markers in my java editor
> (although the tool tip showed the jar file ie., hello.jar). So now I
> compiled and run the program once again I got the output as expected i.e.,
> "Before Hello"
> "Hello from HelloWorld"
> "After Hello"

> Once I got this I decided to remove the after() advice in the World.aj
> and saved it and run the program once again to ensure that my changes to
> the aspect reflect on my code. I got an error, like
> After Hello
> Hello from HelloWorld...
> java.lang.NoSuchMethodError:
> myPackage.World.ajc$after$myPackage_World$2$f69f5afa()V
> at myPackage.HelloWorld.sayHello(HelloWorld.java:28)
> at myPackage.HelloWorld.main(HelloWorld.java:22)
> Exception in thread "main"
> so I put that advice back in and removed the before() advice and did the
> same again. Now I got the following error.
> java.lang.NoSuchMethodError:
> myPackage.World.ajc$after$myPackage_World$2$f69f5afa()V
> at myPackage.HelloWorld.sayHello(HelloWorld.java:28)
> at myPackage.HelloWorld.main(HelloWorld.java:22)
> My initial guess was that the HelloWorld projet is not in the "inpath" of
> HelloAspect project. So I put the HellWorld/bin directory in the "inpath"
> of HelloAspect project. Right after I hit ok I got a problem in my task
> list and it read something like
> "class 'myPackage.HelloWorld' is already woven and has not been built with
> -Xreweavable". That's how far I could go with this.
> Does anyone know how to keep aspects as a library in one project and be
> able to weave the changes in aspect to the code in another project? I
> think I may be missing something here.
> Any "advice" appreciated. My apologies if I am doing something really
> stupid and annoying you all...:)

> Signing off
> lost():withing(aspects)...:)
Re: HelloWorld with a twist [message #585324 is a reply to message #45065] Sun, 19 December 2004 23:20 Go to previous message
Eclipse UserFriend
Originally posted by: sekar.gopinathan.fhlbny.com

I found that by cleaning all the projects, it recompiles and weaves the
aspect fine. After reading some of the threads here, I understand its a
bug.

Thanks
SG

Sekar Gopinathan wrote:

> Hi,

> I used the eclipse AJDT tutorial to create a HelloWorld application and it
> worked great. I added one more advice in addition to the after() advice
> and it goes something like
> public aspect World {
> pointcut greeting() : execution(* HelloWorld.sayHello(..));
> before() : greeting() {
> System.out.println("After Hello");
> }
> after() : greeting() {
> System.out.println("After Hello");
> }
> }
> and my HelloWorld is the same as the one in the tutorial except for the
> output "Hello from HelloWorld" in sayHello() method.

> Now I wanted to make the aspect a library that HelloWorld project can use.
> So I created a HelloAspect project and moved the World.aj aspect into
> that project. Both projects are Aspect projects. Now in the
> HelloAspect project, I set the output variable in AspectJ properties to
> hello.jar(as per the article by Adrian in one of the posts in
> Aspectprogrammer.org.a very good one that) Also, in the HelloWorld
> project, I set the AspectJ aspect path to hello.jar in the HelloAspect
> project. I noticed that I could see the markers in my java editor
> (although the tool tip showed the jar file ie., hello.jar). So now I
> compiled and run the program once again I got the output as expected i.e.,
> "Before Hello"
> "Hello from HelloWorld"
> "After Hello"

> Once I got this I decided to remove the after() advice in the World.aj
> and saved it and run the program once again to ensure that my changes to
> the aspect reflect on my code. I got an error, like
> After Hello
> Hello from HelloWorld...
> java.lang.NoSuchMethodError:
> myPackage.World.ajc$after$myPackage_World$2$f69f5afa()V
> at myPackage.HelloWorld.sayHello(HelloWorld.java:28)
> at myPackage.HelloWorld.main(HelloWorld.java:22)
> Exception in thread "main"
> so I put that advice back in and removed the before() advice and did the
> same again. Now I got the following error.
> java.lang.NoSuchMethodError:
> myPackage.World.ajc$after$myPackage_World$2$f69f5afa()V
> at myPackage.HelloWorld.sayHello(HelloWorld.java:28)
> at myPackage.HelloWorld.main(HelloWorld.java:22)
> My initial guess was that the HelloWorld projet is not in the "inpath" of
> HelloAspect project. So I put the HellWorld/bin directory in the "inpath"
> of HelloAspect project. Right after I hit ok I got a problem in my task
> list and it read something like
> "class 'myPackage.HelloWorld' is already woven and has not been built with
> -Xreweavable". That's how far I could go with this.
> Does anyone know how to keep aspects as a library in one project and be
> able to weave the changes in aspect to the code in another project? I
> think I may be missing something here.
> Any "advice" appreciated. My apologies if I am doing something really
> stupid and annoying you all...:)

> Signing off
> lost():withing(aspects)...:)
Previous Topic:HelloWorld with a twist
Next Topic:How to access 'this'
Goto Forum:
  


Current Time: Sat Jun 21 14:19:28 EDT 2025

Powered by FUDForum. Page generated in 0.05684 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top