开发者

Weaving the same aspect into multiple jars

开发者 https://www.devze.com 2023-04-10 07:11 出处:网络
I\'ve been having problems weaving this project correctly with AspectJ (ajc). Here\'s the situation :

I've been having problems weaving this project correctly with AspectJ (ajc). Here's the situation :

I'm using a benchmarking library called DaCapo Benchmarks, and in it I'm trying to intercept all calls to Iterator.HasNext() and Next() [academic research]. This seems to be working in a vacuum, however DaCapo works in a way such that it's own jar contains other jars which it extracts according to which benchmark I want to run along with it's dependencies 开发者_如何学JAVAand runs it.

I want to intercept all HasNext()s and Next()s with the same aspect so my total is tracked across all the jar files instead of in each individual one.

I hope I'm coming across as clear enough. I'm fully available to answer any questions you might have in order to be able to help me through this weird problem.

P.S. I have the weird feeling it's not actually doable, but a test in eclipse with AJDT (I'm using raw aspectj with ajc for the DaCapo Benchmarks weaving) hints at the possibility.


I know it is too late but may help someone else . .

Whatever i understood from your question is you want to wave same aspect in multiple jars .

So there are 2 ways

  1. if you are using eclipse :

Then create aspect project and go to its properties > click on aspect build option at left panel >select inpath tab at right panel > now click on add external jars > add the jars you want to wave the aspect into >click on OK

again go to its properties > click on aspect build option at left panel >select Output jar tab at right panel >and give the name for new jar you want to create . .>click ok .

create and write your aspect and build or clean your project . It will generate The jar in root directory of project by the name you have given in the "output jar" and this jar will have all the jars you have given in inpath jars with aspect waved . . Thats it . .

  1. If you are using command propmt then :

    Write your aspect for intercepting mehtods you want to .> now fire following command on command prompt :

    ajc -inpath myJar1.jar -inpath myJar2.jar myAspect.java -outjar MyOutputJar.jar

thats it it will generate final jar with all jar you mentioined in inpath . . You can use as many -inpath as many jars you want to wave code into . For any dependency error, give required dependency jars in classpath.


If you are using load-time weaving, it is unlikely that this is possible. There is a circularity problem. You need to weave the JDK, but the weaver needs the JDK to load itself and so many parts of the JDK cannot be woven using LTW.

So, you will need to go with compile time weaving. Something like this will work:

ajc -inpath rt.jar -outjar woven_rt.jar *.aj

I'm not sure if this is the problem you are having, but it might fix things.

0

精彩评论

暂无评论...
验证码 换一张
取 消