user1292755
user1292755

Reputation: 23

AspectJ project as a jar to another project

I have 2 projects. Project A - This is an aspectJ project. For example: It prints the method name and time taken, in console after execution of each method. Project B - It is a sample web project.

I want to add Project A as a Jar to Project B. So whenever I run Project B, it should display what are the method names and time taken.

Since I am new to AspectJ , could someone explain how to do this. Please explain with some sample projects. Thanks in advance.

Upvotes: 0

Views: 493

Answers (1)

kriegaex
kriegaex

Reputation: 67297

You have several options:

  • Use A as an aspect library when compiling B with the AspectJ compiler Ajc. This can be done from command line, from IDE with the right project configuration or, most conveniently, via AspectJ Maven plugin.
  • Use A as an aspect library and B as a weave dependency in a post-processing step with Ajc. As before, this can be done from command line, from IDE with the right project configuration or, most conveniently, via AspectJ Maven plugin.
  • Use load-time weaving (LTW) via -javaagent:/path/to/aspectjweaver.jar command-line switch when starting your Java application containing B and put A on the classpath as an aspect library.

For more information please use your favourite web search engine, specifying search terms like "aspectj ltw", "aspectj maven plugin", "aspectj ajc" or similar.

P.S.: Why should anyone provide one or multiple full sample projects if you are too lazy to provide a single line of code?

Upvotes: 1

Related Questions