AspectJ编译器(AJC)与加载时编织 [英] AspectJ compiler (ajc) vs load-time weaving

查看:482
本文介绍了AspectJ编译器(AJC)与加载时编织的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有几个问题:

  • ajc是否会更改它编译的所有类(甚至是非方面的类)?如果我只精通方面类ant,然后将它们与普通类放在同一个类路径中怎么办?

  • Does ajc change all the classes it compiles (even non-aspect ones)? What if I comiple only aspect classes ant then put them in the same classpath with the common ones?

用ajc编译的项目比使用加载时编织的项目执行得更快吗?

Does the ajc-compiled project perform faster then the one that uses load-time weaving?

如果我需要编写一个与AspectJ一起进行跟踪的库,然后我希望该库可用于任何项目,该怎么办?在这种情况下,加载时编织是唯一的选择吗?

What if I need to write a library, that does tracing with AspectJ, and then I want this library to work with ANY project? Is load-time weaving the only option in this case?

推荐答案

  1. ajc(编译时)将仅更改受方面影响的类.请记住,ajc是Java编译器的扩展(准确地说,它基于Eclipse 3.3的JDT编译器).因此,它将像普通Java编译器一样编译所有Java类.然后,它将另外编织受方面影响的所有类.如果您将各个方面与非方面分开进行编译,那么将不会进行任何编译,也不会对您的方面产生任何影响.但是,您可以将方面放在非方面的汇编的方面路径上(如果非方面是由ajc编译的).这将使您的非方面由您的方面编织而成.
  2. CTW下的启动时间比LTW好得多,但是在加载所有类之后,速度差异应该可以忽略不计.原因是在LTW下,所有类在加载时都是编织的.这意味着类加载需要附加的编织步骤,这在CTW下是不必要的.
  3. 不.如上所述,您可以将方面添加到第二个项目的方面路径中,然后在编译过程中将它们编织起来.
  1. ajc (compile time) will only change classes that are affected by aspects. Remember, ajc is an extension of a Java compiler (to be precise, it is based on Eclipse 3.3's JDT compiler). So, it will compile all your Java classes as would a normal Java compiler. It will then additionally weave all classes that are affected by an aspect. If you compile your aspects separately from your non-aspects then there will be no compile time weaving going on and your aspects will not have any affect. However, you can put your aspects on the aspect path of the compilation of your non-aspects (if your non-aspects are compiled by ajc). This will allow your non-aspects to be woven by your aspects.
  2. Start-up time under CTW is much better than LTW, but after all classes are loaded, speed difference should be negligible. The reason is that under LTW, all classes are woven when they are loaded. This means that classloading requires the additional step of weaving which is not necessary under CTW.
  3. No. As mentioned above, you can add the aspects to your aspect path of the second project, and then they will be woven during compilation.

有关纵横比"路径的更多信息:

More on Aspect path:

http://www.eclipse.org/aspectj/doc/released/devguide/ajc-ref.html

这篇关于AspectJ编译器(AJC)与加载时编织的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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