AspectJ not capture calls from jar file

倖福魔咒の 提交于 2019-12-22 00:41:55

问题


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 ?


回答1:


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.

来源:https://stackoverflow.com/questions/34416329/aspectj-not-capture-calls-from-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!