1

I have a library(say lib1) which comprises of a couple of aspect classes(say aspect1.java and aspect2.java). I want to weave only aspect1.java in my service code. Is this possible using ant iajc target in compile time weaving ? I know this is possible in load time weaving by specifying which aspects to weave in aop.xml.

We have aspectpath in iajc as well, but I am not sure how to configure it to accept individual class files rather than a complete jar file.

<target name="weave-with-ajc">
    <ht-aj:standard-aj-weave>
        <inpath>
            <path path="${classes.dir}" />
        </inpath>
        <aspectpath>
            <path path="${standard.compile.classpath}" />
            <path path="${bp:[Library]pkg.classpath}" />
        </aspectpath>
    </ht-aj:standard-aj-weave>
</target>

I want to weave only a particular aspect and not all the aspects in the library. Please suggest.

roger
  • 269
  • 1
  • 5
  • 20

2 Answers2

0

aop.xml support has been added for compile time weaving as well as per https://bugs.eclipse.org/bugs/show_bug.cgi?id=124460

roger
  • 269
  • 1
  • 5
  • 20
0

Even though the mentioned enhancement is still not implemented, they've provided a simplistic way to explicitly specify aspects to be woven at compile-time. In my case, I am using spring-aspects to weave in AnnotationBeanConfigurerAspect to support @Configurable annotation, and the problem is that is weaves in all aspects found in spring-aspects.jar (@Transactional support, JPA exception translator and so on) which is not what I want (at least I want to have control over this). Based on this post, I am using the following solution:

<iajc destDir="${module.bin.dir}" showWeaveInfo="true" >
   <inpath>
      <pathelement location="${module.bin.dir}" />
   </inpath>
   <classpath>
      <path refid="module.classpath" />
   </classpath>
   <aspectpath refid="module.classpath" />
   <inxml> <!-- this is the important part -->
      <fileset dir="${module.src.dir}">
         <include name="aop-ctw.xml"/>
      </fileset>
   </inxml>
</iajc>

with aop-ctw.xml residing inside the source directory:

<?xml version="1.0"?>
<aspectj>
   <aspect name="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/>
<!-- Now, I don't want these:
    <aspect name="org.springframework.transaction.aspectj.AnnotationTransactionAspect"/>
    <aspect name="org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect"/>
-->
</aspectj>

In case aop-ctw.xml is not found, iajc goes with the standard behavior: all available aspects are woven in.

Pavel S.
  • 1,202
  • 1
  • 13
  • 29