Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1053167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:12:37+00:00 2026-05-16T17:12:37+00:00

I have to use Annotation Processing (apt) and AspectJ in the same Maven project.

  • 0

I have to use Annotation Processing (apt) and AspectJ in the same Maven project.

Both work for themselves, but I need to create aspects based on code created by apt. So I would need binary weaving (the original source files are extended by apt). How can I enable binary weaving within a maven project?

I know the only standard option is to supply a dependency using the weaveDependencies parameter, but this is awful. Is there any other way?

OK, I could embed the AspectJ ant tasks using the Maven Antrun Plugin but I’d hate to resort to that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:12:38+00:00Added an answer on May 16, 2026 at 5:12 pm

    I am apparently the only one who can answer my own questions.

    I have resorted to compiling AspectJ via ant using the Maven Antrun Plugin. Here’s my pom snippet:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.4</version>
        <dependencies>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjtools</artifactId>
                <version>${aspectj.version}</version>
            </dependency>
        </dependencies>
        <executions>
            <execution>
                <id>ajc-compile</id>
                <phase>process-classes</phase>
                <configuration>
                    <tasks>
                        <property name="aspectj.sourcepath"
                            value="${project.basedir}/src/main/aspect" />
                        <property name="aspectj.binarypath"
                            value="${project.build.outputDirectory}" />
                        <property name="aspectj.targetpath"
                            value="${project.build.directory}/aspectj-classes" />
                        <property name="scope_classpath" refid="maven.compile.classpath" />
                        <property name="plugin_classpath" refid="maven.plugin.classpath" />
                        <ant antfile="ajc-ant.xml" />
                    </tasks>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
            <execution>
                <id>ajc-test-compile</id>
                <phase>process-test-classes</phase>
                <configuration>
                    <tasks unless="maven.test.skip">
                        <property name="aspectj.sourcepath"
                            value="${project.basedir}/src/test/aspect;${project.basedir}/src/main/aspect" />
                        <property name="aspectj.binarypath"
                            value="${project.build.testOutputDirectory}" />
                        <property name="aspectj.targetpath"
                            value="${project.build.directory}/aspectj-test-classes" />
                        <property name="scope_classpath" refid="maven.test.classpath" />
                        <property name="plugin_classpath" refid="maven.plugin.classpath" />
                        <ant antfile="ajc-ant.xml" />
                    </tasks>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    I compile java classes first (and let APT do it’s stuff), use the compiled classes as binary input for aspectj, compile aspectj into a new folder and move the resulting woven classes to the original compile directory, overwriting the non-aspectj classes. Here’s my ant XML file (the nice part is that I can use it for both compile and test-compile):

    <project basedir="." default="ajc">
        <path id="classpath">
            <pathelement path="${scope_classpath}" />
            <pathelement path="${plugin_classpath}" />
        </path>
        <taskdef
            classname="org.aspectj.tools.ant.taskdefs.AjcTask"
            name="iajc" classpathref="classpath" />
        <target name="ajc">
            <iajc
                sourceroots="${aspectj.sourcepath}"
                inpath="${aspectj.binarypath}"
                destdir="${aspectj.targetpath}"
                classpathref="classpath"
                source="1.6"
                target="1.6"
            />
            <move todir="${aspectj.binarypath}">
                <fileset dir="${aspectj.targetpath}">
                    <include name="**/*.class" />
                </fileset>
            </move>
        </target>
    </project>
    

    In the next step I have now created a Maven Plugin that does all this ant calling internally. While I can’t share the code here, I’ll show how it simplified POM configuration:

    <plugin>
        <groupId>com.myclient.maven.plugins</groupId>
        <artifactId>maven-ajc-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        <executions>
            <execution>
                <id>compile-ajc</id>
                <goals>
                    <goal>compile</goal>
                </goals>
            </execution>
            <execution>
                <id>testcompile-ajc</id>
                <goals>
                    <goal>test-compile</goal>
                </goals>
                <configuration>
                    <aspectSourcePath>${project.basedir}/src/main/aspect</aspectSourcePath>
                </configuration>
            </execution>
        </executions>
        <configuration>
    
        </configuration>
    </plugin>
    

    Using ANT / GMaven integration, it was easy to assembly the parameters combining the powers of Maven, Groovy and Ant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have use the TryUpdateModel method on the controllers but now I need to
I have and followed several Annotation Processing Tool (APT) guides (such as 1 and
Does anyone know if it's possible to have a bundle use the annotation reader
I have use semantic-analyze-proto-impl-toggle to switch between the function's proto and impl, but when
Hello I have use DOMDocs in the past but I am stuck how to
I'm just starting to learn AspectJ, and I have use-case for say, User login.
I have a JSP page called CreateProcessGroup.jsp and I use an annotation controller to
I'm using java 6 annotation processing api. I have followed the following excellent tutorial
I have a system which is using Spring for dependency injection. I use annotation-based
I have seen other thread with similar issue but was not able to work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.