Search code examples
mavenaspectj-maven-plugin

Can I hide ***$AjcClosure*.class files created by aspectj-maven-plugin?


I am using aspectj-maven-plugin to generate loggers in methods, and the approach is annotation driven.

Upon compiling, for every method the annotation is defined, I can see a ***$AjcClosure*.class file getting generated in my respective target class file folder.

Issues :

  1. Although this is a compile time activity, is there any way I can avoid having these classes sitting in my class file folder once compilation is over?

  2. If not, what is the purpose of these classes and won't they affect the size of the jar/war file getting created, and thus an overall overhead for every single annotation being added in the application?

Java Version : 1.7 & AspectJ Maven Plugin current configuration :

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.5</version>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
        <complianceLevel>1.7</complianceLevel>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Solution

  • After doing several trials and errors I figured that @Around advice is causing these classes to be created. Please refer White paper on optimizing Aspects for more details.

    Now, I am using @Before & @After advices to achieve the purpose of logging, before and after the method.

    I may be wrong, but this worked for me. Please feel free to post your comments.