Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] aspectJ with packaged classes

I tried that too. Okay, here is the exact detail of what i am doing:

1. I created a Java application with a method which prints 'Hello World'
2. I created an AspectJ project which basically prints 'hello To You Too' after any method execution.
3. In the Inpath of the AspectJ project, i added the jar of the java application.
4. In the classpath of the Java project, i added the AspectJ project.
5. I ran the java project.

I see 'Hello World'. :(
Have i understood the concept of Inpath wrongly? Am i doing something i am not supposed to do? Should i be doing something more?
This seems like a simple enough example, but i am unable to get it to work!

Regards,
Anirudh

On 5/23/07, Matt Chapman <mpchapman@xxxxxxxxx> wrote:
Maybe you're going wrong at step 2 below. You can run as a regular
Java application, but you need to select the AspectJ project in the
Run configuration.

On 22/05/07, Anirudh Chandrakant < anirudh.chandrakant@xxxxxxxxx> wrote:
> Hi Matt,
>
> Thanks for the help.
>
> I really must be the dumbest person on this list, i still havent been able
> to to get it to work :(
>
> Firstly, here is what i dummy code looks like:
>
> HelloWorld.java
>  ---------------------
> public class HelloWorld {
>
>      public static void main(String[] args) {
>         callHelloWorld();
>      }
>
>
>      public static void callHelloWorld() {
>         System.out.println ("Hello World");
>     }
>  }
>
> HelloAspect.aj
> ----------------------
> public aspect HelloAspect {
>
>     pointcut callHelloWorld() :
>          execution(* *(..));
>
>
>      after() : callHelloWorld() {
>         System.out.println("Hello To You Too!");
>     }
> }
>
> These are in two different projects (only the second file in a AspectJ
> project, the first one is a simple java project). I added the helloworld.jar
> as a inpath jar in the aspectj project. I also
> 1) turned on the option to see the info in the Problems view and i see the
> info on join-points and
> 2) tried to run it as a aspectJ application and i can select HelloWorld as
> the main class in the configuration.
>
> But, when i execute it - i get only "Hello World". When i put both the
> classes in the same project and run it, i get the right result.
>
> What am i doing wrong?!
>
> Thanks,
> Anirudh
>
>
> On 5/22/07, Matt Chapman <mpchapman@xxxxxxxxx> wrote:
> > After step 3, try adding the 'Hello World' jar file to the AspectJ
> > project's in-path. The weaving will then occur in the AspectJ project,
> > and the woven version of the Hello World class will be written to the
> > output folder of the AspectJ project. You could use the Navigator view
> > to check this. You can then run the woven class by creating a run
> > configuration for the AspectJ project and entering the name of the
> > class. To confirm that weaving is happening, you can also turn on a
> > compiler option: AspectJ compiler > Information > Output weaving info
> > messages to problems view.
> >
> > This article may also be useful background reading:
> >
> http://www.eclipse.org/articles/Article-Introducing-AJDT/article.html
> >
> > Hope that helps,
> >
> > Matt.
> >
> > On 21/05/07, Anirudh Chandrakant <anirudh.chandrakant@xxxxxxxxx > wrote:
> > > Hi,
> > >
> > > Thanks for that, it makes things a little clearer.
> > >
> > > But i am still facing a few problems. Here is what i did:
> > >
> > > 1. I created a Java project with one class which basically prints 'Hello
> World'
> > > 2. I packaged this into a jar and exported it to a location.
> > > 3. I created a AspectJ project with one aspect which prints a message
> > > after the call to the method which prints 'Hello World'.
> > > 4. I packaged this as a 'Jar File with AspectJ support' and exported it.
> > > 5. When i execute it with the command you have specified, all i can
> > > see is 'Hello World' with no message from the aspect.
> > >
> > > I thought there might be something wrong with my code, so i put the
> > > Hello World class in the aspect project. When i ran it, it displayed
> > > the right information.
> > >
> > > Am i doing something wrong? Do i need to do something more?
> > >
> > > Thanks again,
> > > Anirudh
> > >
> > > On 5/21/07, Sérgio Agostinho < sergioag@xxxxxxxxxxxxx> wrote:
> > > >
> > > >  Hello there,
> > > >
> > > >  You will need to do something like this:
> > > >
> > > >  $ java -classpath
> > > > ".:aspectjrt.jar:your_aspectj_project.jar" -jar
> > > > your_java_project.jar
> > > >
> > > >  This assumes that you are keeping the aspectJ runtime library and
> your
> > > > aspects JARs in the same directory as to your application. It also
> assumes
> > > > that your are creating a JAR file with your aspectJ project.
> > > >
> > > >  Hope this helps,
> > > >
> > > >  Anirudh Chandrakant wrote:
> > > > Thank you so much for that information, dean!
> > > >
> > > >  I still a little difficulty figuring out how this would work. Here is
> the
> > > > scenario:
> > > >  I have a Java project. I do not have the sources, i only have the
> jar. I
> > > > would like to weave aspects into this. I create an aspectJ project and
> > > > define the aspects i want. I add the Java jar in the inpath of the
> aspectJ
> > > > project.
> > > >
> > > >  Now:
> > > >  1. How do i execute the aspectJ project without a 'main' class? If i
> have
> > > > to specify the 'main' class, what do i do in the main class?
> > > >  2. How does it all work? If i execute the jar file, how are the
> aspects
> > > > weaved in? How is the jar aware of the aspects?
> > > >
> > > >  Maybe i am missing something extremely simple here, but i am unable
> to
> > > > figure out how this whole setting would function.
> > > >
> > > >  Thanks in advance,
> > > >  Anirudh
> > > >
> > > >
> > > > On 5/21/07, Dean Wampler < dean@xxxxxxxxxxxxxxxxxxxxx > wrote:
> > > > >
> > > > > Yes, use the "-inpath" option for ajc to specify the jars you want
> to
> > > > "weave". Here's a good blog on the different path options.
> > > > >
> > > > >
> > > > >
> > > >
> http://www.aspectprogrammer.org/blogs/adrian/2004/10/three_paths_sta.html
> > > > >
> > > > >
> > > > > dean
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On May 21, 2007, at 6:05 AM, Anirudh Chandrakant wrote:
> > > > >
> > > > >
> > > > > Hi,
> > > > >
> > > > > I am a new entrant into the aspectJ world and i am enjoying the ride
> so
> > > > far.
> > > > > I have used aspectJ with an existing project and it works as
> desired.
> > > > >
> > > > > Now, if i have a Java project but i do not have the source files (i
> only
> > > > have the jar), can i still use aspectJ? (I know the signatures of all
> the
> > > > methods that i want to insert my pointcuts into)
> > > > >
> > > > > The demo shows conversion of a normal project into an aspectJ
> project (in
> > > > a step similar to instrumentation), i was wondering if this was
> possible
> > > > with packaged classes.
> > > > >
> > > > > Thanks in advance,
> > > > > Anirudh
> > > > >
> > > > > _______________________________________________
> > > > > 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
> > > > > http://www.aspectprogramming.com
> > > > > http://www.contract4j.org
> > > > >
> > > > >
> > > > > 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
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >  --
> > > >  'Tomorrow's what i am waiting for, but i can wait a little more' -
> Calvin
> > > > (Bill Watterson) ________________________________
> > > >
> > > > _______________________________________________
> > > > aspectj-users mailing list
> > > > aspectj-users@xxxxxxxxxxx
> > > >
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > >
> > > >
> > > >
> > > >  --
> > > > Sérgio Agostinho
> > > > Research Assistant
> > > >
> > > > CITI - Centre for Informatics and Information Technologies
> > > > Faculdade de Ciências e Tecnologia
> > > > Monte da Caparica
> > > > 2829-516 Caparica
> > > > Portugal
> > > >
> > > > E-mail: sergioag@xxxxxxxxxxxxx
> > > > URL: http://citi.di.fct.unl.pt
> > > > Phone: +351 21 2948300 (ext. 10771)
> > > >
> > > >
> > > > _______________________________________________
> > > > aspectj-users mailing list
> > > > aspectj-users@xxxxxxxxxxx
> > > >
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > >
> > > >
> > >
> > >
> > > --
> > > 'Tomorrow's what i am waiting for, but i can wait a little more' -
> > > Calvin (Bill Watterson)
> > > _______________________________________________
> > > aspectj-users mailing list
> > > aspectj-users@xxxxxxxxxxx
> > > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
>
>
>
> --
> 'Tomorrow's what i am waiting for, but i can wait a little more' - Calvin
> (Bill Watterson)
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



--
'Tomorrow's what i am waiting for, but i can wait a little more' - Calvin (Bill Watterson)

Back to the top