适用于Java 8的Aspectj Maven插件能够运行时编织方面,但无法编译时 [英] aspectj maven plugin for java 8 is able to runtime weave aspects but not compile time

查看:126
本文介绍了适用于Java 8的Aspectj Maven插件能够运行时编织方面,但无法编译时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我针对Java 8的Aspectj Maven插件的配置:

Here is my configuration of aspectj maven plugin for java 8:

<plugin>
       <groupId>org.codehaus.mojo</groupId>
       <artifactId>aspectj-maven-plugin</artifactId>
       <version>1.8</version>
       <configuration>
                <showWeaveInfo>true</showWeaveInfo>
                <source>1.8</source>
                <target>1.8</target>
                <Xlint>ignore</Xlint> 
                <complianceLevel>1.8</complianceLevel>
                <encoding>UTF-8</encoding>
                <verbose>false</verbose>
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>external project containing aspects</groupId>
                        <artifactId>external project containing aspects</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
       </configuration>
       <executions>
         <execution>    
           <goals>
             <goal>compile</goal>
             <goal>test-compile</goal>
           </goals>
         </execution>
       </executions>
       <dependencies>
        <dependency>
           <groupId>org.aspectj</groupId>
           <artifactId>aspectjtools</artifactId>
           <version>1.8.7</version>
         </dependency>
       </dependencies> 
  </plugin>

当我添加如下所示的surefire插件时,我能够在加载时间上编织各个方面.

When I add a surefire plugin like below, I am able to weave the aspects on load-time.

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <configuration>
<argLine>javaagent:${user.home}/.m2/repository/org/aspectj/aspectjweaver/1.8.7/aspectjweaver-1.8.7.jar</argLine>
    </configuration>
 </plugin>

为了确保我的方面被击中,我在其中添加了println语句.但是,当尝试进行编译时,它们并没有在控制台上显示.请帮我.我不知道我的配置中缺少什么.无法弄清楚各方面为何没有受到打击.

To make sure that my aspect is hit, I have added println statements in it. But they are not getting shownup on the console when trying to do compile time weaving. Please help me. I dont know what I am missing in my configuration. Not able to figure out why the aspects are not getting hit.

推荐答案

配置没有问题.问题是,我的方面在aop.xml文件中被定义为抽象,其具体实现方式也是如此.这就是在编译时未加载它们的原因.因此,我将其具体化,并奏效了.

No issue with the configuration. The problem was, my aspects were defined as abstract with their concrete implementation in the aop.xml file. That is the reason they were not loaded at compile time. So I made them concrete aspects and it worked.

这篇关于适用于Java 8的Aspectj Maven插件能够运行时编织方面,但无法编译时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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