shan
shan

Reputation: 111

aop.xml not getting picked by Maven

Maven is not able to package the aop.xml file when we are using spring-agent.jar file.

We are using Surefire for running unit test cases and jacoco for getting the code coverage.

We are not seeing any issues with spring-agent but aspects are not getting called during run time. We have placed the aop.xml under META-INF folder but it is not getting picked up.

Any idea or pointers on how to make Maven pick up aop.xml file and package it inside the META-INF folder?

this is my pom.xml file

*edit**

this is my pom.xml.. some stuff i removed

                <groupId>project-Web</groupId>
                <artifactId>project-Web</artifactId>
                <version>0.0.1-SNAPSHOT</version>
                <packaging>war</packaging>
                <name>project-Web</name>
                <properties>
                                <hibernate.version>4.2.3.Final</hibernate.version>
                                <spring.version>3.2.3.RELEASE</spring.version>
                                <spring.security.version>3.2.1.RELEASE</spring.security.version>
                                <jersey.version>1.8</jersey.version>
                                <project.dir>${basedir}</project.dir>
                                <project.libdir>${project.dir}/lib</project.libdir>
                                <skipTests>false</skipTests>

                </properties>
                <repositories>
                                <repository>
                                                <id>maven-repo</id>
                                                <url>http://maven.apache.org</url>
                                </repository>
                </repositories>
                <dependencies>
                                                <dependency>
                                                <groupId>commons-validator</groupId>
                                                <artifactId>commons-validator</artifactId>
                                                <version>1.3.1</version>
                                </dependency>
                                <dependency>
                                                <groupId>org.apache.ant</groupId>
                                                <artifactId>ant-apache-oro</artifactId>
                                                <version>1.9.3</version>
                                </dependency>
                                                <dependency>
                                                <groupId>commons-discovery</groupId>
                                                <artifactId>commons-discovery</artifactId>
                                                <version>0.4</version>
                                                <scope>compile</scope>
                                </dependency>
                                <dependency>
                                                <groupId>com.google.code.gson</groupId>
                                                <artifactId>gson</artifactId>
                                                <version>2.2.4</version>
                                </dependency>

                                <dependency>
                                                <groupId>junit</groupId>
                                                <artifactId>junit</artifactId>
                                                <version>4.11</version>
                                                <scope>test</scope>
                                </dependency>
                                <dependency>
                                                <groupId>commons-codec-1.3</groupId>
                                                <artifactId>commons-codec-1.3.jar</artifactId>
                                                <version>1.0</version>
                                                <scope>system</scope>
                                                <systemPath>${project.libdir}/commons-codec-1.3.jar</systemPath>
                                </dependency>


                                <dependency>
                                                <groupId>org.springframework</groupId>
                                                <artifactId>spring-aop</artifactId>
                                                <version>${spring.version}</version>
                                </dependency>
                                <dependency>
                                                <groupId>org.springframework</groupId>
                                                <artifactId>spring-core</artifactId>
                                                <version>${spring.version}</version>
                                </dependency>
                                <dependency>
                                                <groupId>org.springframework</groupId>
                                                <artifactId>spring-context</artifactId>
                                                <version>${spring.version}</version>
                                </dependency>
                                <dependency>
                                                <groupId>org.springframework</groupId>
                                                <artifactId>spring-context-support</artifactId>
                                                <version>${spring.version}</version>
                                </dependency>
                                <dependency>
                                                <groupId>org.springframework</groupId>
                                                <artifactId>spring-web</artifactId>
                                                <version>${spring.version}</version>
                                </dependency>


                                <dependency>
                                                <groupId>org.springframework</groupId>
                                                <artifactId>spring-test</artifactId>
                                                <version>${spring.version}</version>
                                </dependency>



                                <dependency>
                                                <groupId>org.springframework.integration</groupId>
                                                <artifactId>spring-integration-core</artifactId>
                                                <version>2.0.3.RELEASE</version>
                                                <scope>test</scope>
                                </dependency>

                                <dependency>
                <groupId>org.springframework.integration</groupId>
                <artifactId>spring-integration-mail</artifactId>
                <version>2.0.3.RELEASE</version>
                <scope>test</scope>
</dependency>


    <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjrt</artifactId>
                    <version>1.6.7</version>
    </dependency>

 <dependency>
                                                <groupId>org.aspectj</groupId>
                                                <artifactId>aspectjweaver</artifactId>
                                                <version>1.8.4</version>
                                                <scope>system</scope>
                                                <systemPath>${project.libdir}/aspectjweaver-1.8.4.jar</systemPath>
                                </dependency>

                                <dependency>
                                                <groupId>org.springagent</groupId>
                                                <artifactId>spring-agent</artifactId>
                                                <version>2.5.6</version>
                                                <scope>system</scope>
                                                <systemPath>${project.libdir}/spring-agent-2.5.6.jar</systemPath>
                                </dependency>

                </dependencies>
                <profiles>
                                <profile>
                                                <id>local</id>
                                                <activation>
                                                                <activeByDefault>true</activeByDefault>
                                                </activation>
                                                <properties>
                                                                <env>local</env>
                                                </properties>
                                </profile>
                                <profile>
                                                <id>dev</id>
                                                <properties>
                                                                <env>dev</env>
                                                </properties>
                                </profile>
                                <profile>
                                                <id>stage</id>
                                                <properties>
                                                                <env>stage</env>
                                                </properties>
                                </profile>
                                <profile>
                                                <id>lt</id>
                                                <properties>
                                                                <env>lt</env>
                                                </properties>
                                </profile>
                                <profile>
                                                <id>prod</id>
                                                <properties>
                                                                <env>prod</env>
                                                </properties>
                                </profile>

                </profiles>
                <build>



                               <plugins>
                                                <plugin>
                                                                <artifactId>maven-resources-plugin</artifactId>
                                                                <version>2.6</version>
                                                                <executions>
                                                                                <execution>
                                                                                                <id>generate-resources</id>
                                                                                                <phase>process-sources</phase>
                                                                                                <goals>
                                                                                                                <goal>copy-resources</goal>
                                                                                                </goals>
                                                                                                <configuration>
                                                                                                                <overwrite>true</overwrite>
                                                                                                                <outputDirectory>${project.build.directory}/classes/config</outputDirectory>
                                                                                                                <resources>
                                                                                                                                <resource>
                                                                                                                                                <directory>${project.basedir}/src/main/resources/config/${env}</directory>
                                                                                                                                                <includes>
                                                                                                                                                                <include>**/*.properties</include>
                                                                                                                                                </includes>
                                                                                                                                                <excludes>
                                                                                                                                                                <exclude>${project.basedir}/src/main/resources/config/${env}</exclude>
                                                                                                                                                </excludes>
                                                                                                                                </resource>
                                                                                                                </resources>
                                                                                                </configuration>
                                                                                </execution>
                                                                </executions>
                                                </plugin>
                                                <plugin>
                                                                <groupId>org.apache.maven.plugins</groupId>
                                                                <artifactId>maven-compiler-plugin</artifactId>
                                                                <version>2.0.2</version>
                                                                <configuration>
                                                                                <source>1.6</source>
                                                                                <target>1.6</target>
                                                                </configuration>
                                                </plugin>
                                                <plugin>
                                                                <groupId>org.apache.maven.plugins</groupId>
                                                                <artifactId>maven-war-plugin</artifactId>
                                                                <version>2.4</version>
                                                                <configuration>
                                                                                <warName>${project.artifactId}-${project.version}</warName>
                                                                                <webResources>
                                                                                                <resource>
                                                                                                                <directory>${project.libdir}</directory>
                                                                                                                <targetPath>WEB-INF/lib</targetPath>
                                                                                                                <includes>
                                                                                                                                <include>**/*</include>
                                                                                                                </includes>
                                                                                                </resource>
                                                                                </webResources>
                                                                </configuration>
                                                </plugin>
                                                <plugin>
                                                                <groupId>org.apache.maven.plugins</groupId>
                                                                <artifactId>maven-ear-plugin</artifactId>
                                                                <version>2.9</version>
                                                                <configuration>
                                                                                <skinnyWars>true</skinnyWars>
                                                                                <modules>
                                                                                                <webModule>
                                                                                                                <groupId>${project.groupId}</groupId>
                                                                                                                <artifactId>project-Web</artifactId>
                                                                                                                <contextRoot>/dev</contextRoot>
                                                                                                </webModule>
                                                                                </modules>
                                                                </configuration>
                                                                <dependencies>
                                                                                <dependency>
                                                                                                <groupId>comprojectservices</groupId>
                                                                                                <artifactId>project-Web</artifactId>
                                                                                                <version>0.0.1-SNAPSHOT</version>
                                                                                                <type>war</type>
                                                                                                <scope>system</scope>
                                                                                                <systemPath>${project.basedir}/target/project-Web-0.0.1-SNAPSHOT.war</systemPath>
                                                                                </dependency>
                                                                </dependencies>
                                                </plugin>
            <plugin>
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>aspectj-maven-plugin</artifactId>
     <version>1.3</version>
     <executions>
         <execution>
             <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>     

             <goals>
                 <goal>compile</goal> 
                 <goal>test-compile</goal>    
             </goals>
         </execution>
    </executions>
</plugin>
            <plugin>
    <groupId>org.apache.maven.plugins</groupId>


   <artifactId>maven-surefire-plugin</artifactId>
    <version>2.4</version>
    <configuration>
            <forkMode>once</forkMode>
            <argLine>
            -javaagent:${settings.localRepository}/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.8.4/aspectjweaver-1.8.4.jar
        </argLine>
            <useSystemClassloader>true</useSystemClassloader>
    </configuration>
</plugin>
                                </plugins>
                                <resources>
      <resource>
        <directory>test/resources</directory>
        <includes>
          <include>aop.xml</include>
        </includes>
        <targetPath>META-INF</targetPath>
      </resource>
    </resources>
                </build>
</project>


    still aop.xml is not getting picked up, becase aspects are not getting weaved.
    i tried all approaches but not getting any clue where i am going wrong.
    **BTW :** both the javaagents are in one line only.
    does maven-resource-plugin is causing any issue here?

Upvotes: 0

Views: 2435

Answers (2)

mystarrocks
mystarrocks

Reputation: 4088

If you just want to package a custom aop.xml that you already have with you (as opposed to generating it through the aspectj-maven-plugin) inside the META-INF, you would only need to tweak the <resources> section of the <build> configuration like this:

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>aop.xml</include> <!-- ensures aop.xml ends inside the META-INF -->
        </includes>
        <targetPath>META-INF</targetPath>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <excludes>
          <exclude>aop.xml</exclude> <!-- ensures all other resources end inside the default target path -->
        </excludes>
      </resource>
    </resources>
    ...
  </build>

This assumes you've placed your aop.xml file under src/main/resources - you can configure this according to your needs.

Upvotes: 1

mystarrocks
mystarrocks

Reputation: 4088

Here's the minimal configuration you will need to let the aspectj-maven-plugin generate the aop.xml under META-INF to be used for load-time-weaving later. Be sure to include the aspectjrt dependency to your project too.

You can try this on any project - even a barebone Maven project should be enough to test this and verify that the META-INF\aop.xml is created inside your archive. Of course you can tweak the configuration to suit your needs.

  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.7</version>
        <configuration>
          <outxml>true</outxml>
          <outxmlfile>META-INF/aop.xml</outxmlfile>
          <source>1.6</source>
          <target>1.6</target>
          <complianceLevel>1.6</complianceLevel>
        </configuration>
        <executions>
          <execution>
            <id>Generate aop.xml for LTW</id>
            <goals>
              <goal>compile</goal>
            </goals>
            <phase>compile</phase>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

Upvotes: 0

Related Questions