Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Aspect J with Core Java application

That is quite straightforward.

Compilation
=========
You have two choices, you can either weave your application as it is
built (compile time weaving) or weave your application after it is
built (binary weaving).

- compile time weaving - switch from using javac to using ajc, the
aspects are then compiled and woven as part of the app build.  Whether
you are using command line or ant or maven, you can plug in AspectJ.

- binary weaving - after the main build finishes, use ajc to binary
weave your application jar into a new jar:
ajc -inpath myApplication.jar -outjar wovenApplication.jar com/foo/MyAspect.aj

Binary weaving might be a quick way for you to start out and see if
things are going to work for you.

Aspects
======
The aspects and advice can be pretty sophisticated, but the basic
pattern is just:

aspect EntryExitLogger {
  pointcut scope(): within(com.foo.mypackages..*); // define packages
of interest

  before(): execution(* *(..)) && scope() {
    System.out.println("Entering "+thisJoinPointStaticPart);
  }

  after(): execution(* *(..)) && scope() {
    System.out.println("Exiting "+thisJoinPointStaticPart);
  }
}

You may want to make that a pertypewithin aspect if going for a Log4J
style logging - that has been discussed a few times in the archives
here.

cheers
Andy

On 10 October 2011 03:25, sumitkushwaha <sumit_kumar19@xxxxxxxxxxx> wrote:
> hi
>
> I have a core java(1.5) application (Its not a web based application) in
> which we have to incorporate logging framework for each and every method
> that executes. I have a few question:
> 1) Can we incorporate aspect j with core java application ?
> 2) If yes thn how to create logging advice.
> 3) What all configuration changes will be required to achieve this
>
>
> Thanks
> Sumit
>
> --
> View this message in context: http://aspectj.2085585.n4.nabble.com/Aspect-J-with-Core-Java-application-tp3889772p3889772.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top