0

Mavenaop.xml当我们使用文件时无法打包spring-agent.jar文件。

我们Surefire用于运行单元测试用例和jacoco获取代码覆盖率。

我们没有看到任何问题,spring-agentaspects在运行时没有被调用。我们已经放置了aop.xml下面的META-INF文件夹,但它没有被拾取。

关于如何让 Maven 拾取aop.xml文件并将其打包到META-INF文件夹中的任何想法或指示?

这是我的 pom.xml 文件

*编辑**

这是我的 pom.xml .. 我删除了一些东西

                <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?
4

2 回答 2

1

如果您只想在. aop.xml_aspectj-maven-pluginMETA-INF<resources><build>

  <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>

这假设您已将aop.xml文件放在下面src/main/resources- 您可以根据需要进行配置。

于 2015-01-09T18:38:57.710 回答
0

这是您需要aspectj-maven-plugin生成aop.xml的最低配置META-INF,以便load-time-weaving以后使用。确保也将aspectjrt依赖项包含到您的项目中。

你可以在任何项目上尝试这个——即使是一个准系统Maven项目也应该足以测试它并验证它META-INF\aop.xml是在你的存档中创建的。当然,您可以调整配置以满足您的需求。

  <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>
于 2015-01-09T14:46:30.417 回答