Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Only enabling specific aspects when weaving with ajc

I have the following situation, and while I have solved the problem using aspectj's load-time weaver, I would like to see if it's possible to handle this problem using ajc at compile time.

1. I have built a java library (the jar file is perf4j.jar) that contains a number of aspects created using @AspectJ style syntax. That is, perf4j.jar was just compiled using javac, NOT ajc.
2. I would like to enable other developers to use my aspects by marking some of their methods with a "Profiled" annotation, which is also defined in perf4j.jar. Thus, my aspects all have a pointcut that looks like: execution(* *(..)) && @annotation(profiled)
3. Right now everything works fine if I use load-time weaving with an aop.xml that looks like this:

<aspectj>
  <!-- we only want to weave in the log4j TimingAspect -->
  <aspects>
    <aspect name="org.perf4j.log4j.aop.
TimingAspect"/>
  </aspects>

  <weaver options="-verbose -showWeaveInfo">
    <!-- other developers specify here their classes they wish to weave -->
    <include within="com.third.party.developer.*"/>
  </weaver>
</aspectj>
4. Is there a way that I can replicate this behavior at compile time using ajc? The problem I have with ajc is that, as far as I can tell, there is no way to specify the class names of the aspects I want to include like there is with aop.xml. That is, my perf4j.jar contains a bunch of different aspects, but other developers are only going to want to chose one of those aspects to weave into their classes. Do I need to generate a different jar file for each aspect? Also, right now I'm just delivering my aspects in a javac-compiled jar (which works because they are @AspectJ-style aspects). Do I need to first use ajc to generate a read-only aspect library in a separate jar?

Thanks for any and all help!

Alex Devine

Back to the top