如何使用maven构建aspectj项目? [英] How to build aspectj project using maven?

查看:119
本文介绍了如何使用maven构建aspectj项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse ide中创建了一个Aspectj项目,但我需要使用maven构建它。

I have created a Aspectj Project in Eclipse ide but i need to build it using maven.

我有maven-aspectj插件但不知道如何使用它。

I have maven-aspectj plugin but don't know how to use it.

推荐答案

以下是我为实现这一目标而采取的步骤。这给了我编译时编织。如果您需要其他策略,显然您需要另一种方法(例如 Spring运行时AOP代理的AOP

Below are the steps that I followed to get this working. This gave me compile-time weaving. If you need other strategies, clearly you need another approach (such as Spring AOP for runtime AOP proxies).


  1. 添加属性以标准化您使用的AspectJ版本:

  1. Add a property to standardize the AspectJ version that you use:

<properties>
    <aspectj.version>1.7.2</aspectj.version>
  ...


  • 添加运行时依赖项:

  • Add the runtime dependency:

    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>${aspectj.version}</version>
    </dependency>
    


  • 添加AspectJ Maven插件:

  • Add the AspectJ Maven plugin:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.4</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>test-compile</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
          </dependency>
          <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>${aspectj.version}</version>
          </dependency>
        </dependencies>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
          <forceAjcCompile>true</forceAjcCompile>
        </configuration>
      </plugin>
    


  • 我不确定是否 forceAjcCompile 非常有意义,但是我已经看到了某些方面没有一致应用的情况。我责备这个(现在)在Eclipse上覆盖类文件或其他东西,因此 forceAjcCompile

    I'm not sure if forceAjcCompile makes a lot of sense, really, but I've seen some cases where the aspects weren't consistently applied. I'm blaming this (for now) on Eclipse overwriting class files or something, hence the forceAjcCompile.

    其他我做的事情:


    1. 添加 src / main / aspects 作为额外的源目录( build-helper-maven-plugin 插件)。只是因为它在Eclipse中看起来不错

    2. 添加 pluginExecution / pluginExecutionFilter AspectJ插件( lifecycle-mapping 插件)并将其设置为执行 runOnIncremental ,以便在以下方面(重新)应用方面在Eclipse中编码和测试(使用m2e)

    1. Add src/main/aspects as an extra source directory (build-helper-maven-plugin plugin). Just because it looks good in Eclipse
    2. Add a pluginExecution/pluginExecutionFilter for the AspectJ plugin (lifecycle-mapping plugin) and set it to execute and runOnIncremental, so that also aspects are (re-)applied when coding and testing in Eclipse (using m2e)

    这篇关于如何使用maven构建aspectj项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆