AspectJ不捕获来自jar文件的调用 [英] AspectJ not capture calls from jar file

查看:115
本文介绍了AspectJ不捕获来自jar文件的调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.currentTimeMillis()被调用时,我想执行特定的操作。我使用AspectJ如下。

  public aspect CurrentTimeInMillisMethodCallChanger {
long around():
调用(public static native java.lang.System.currentTimeMillis()){
//提供自己的实现
}
}

当应用程序的任何方法调用 System.currentTimeMillis()时,此程序工作正常。然而,当$ code> System.currentTimeMillis()从jar文件中的方法调用时,则不执行。我使用(packageofJarFile。*)中的,但它不起作用。



我正在使用Eclipse。 p>

请让我知道我需要添加以上代码来支持(特定)jar文件的调用?

解决方案

您需要为Eclipse(AJDT)设置AspectJ插件,以便编写库代码,而不仅仅是您自己的类文件。您可以通过转到项目属性 - > AspectJ Build - > Inpath选项卡,并添加您想要编写的方面的jar文件。以下是对话框的屏幕快照:

这样编写的图书馆类将被转储到您的输出类文件夹中,除非您在同一属性页的第三个选项卡上设置了一个输出jar


I want to do specific action when System.currentTimeMillis() is called. I use AspectJ as below to do that.

public aspect CurrentTimeInMillisMethodCallChanger {
    long around(): 
    call(public static native long java.lang.System.currentTimeMillis()) {
        //provide my own implementation 
    }
}

This program works fine when System.currentTimeMillis() is called in any method of the application.

However, when System.currentTimeMillis() is called from method inside a jar file then around is not executed. I used within(packageofJarFile.*), but it does not work.

I am using Eclipse.

Please let me know what I need to add to the above code to support call from (specific) jar file as well ?

解决方案

You need to set up the AspectJ plugin for Eclipse (AJDT), so that it weaves library code as well, not just your own class files. You can do this by going to Project Properties -> AspectJ Build -> Inpath tab and add the jar files you want to be weaved by your aspects. Here is a screenshot of the dialog: The library classes weaved like this will be dumped in your output classes folder unless you set up an Output jar on the third tab of the same properties page.

这篇关于AspectJ不捕获来自jar文件的调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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