AspectJ - Compile Java source with precompiled aspects

与世无争的帅哥 提交于 2020-01-03 01:54:06

问题


Let's say I have few aspects, which I have already compiled, and now I just want to compile single source file, but without recompiling the aspects, since it takes a lot of time. Is there any way to do so?

For example, I have the following:

  • Trace.aj
  • Log.aj
  • Test.java

All of them were compiled during my "build-all", and now I've changed Test.java and wants to recompile it using the (already compiled) aspects.


回答1:


Use load-time weaving.

http://www.aspectprogrammer.org/blogs/adrian/2004/05/loadtime_weavin.html

Here's how to do it in eclipse: http://www.eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html#enabling-load-time-weaving




回答2:


I'm not sure load time weaving is the right approach in this case. You typically use load time weaving when you want to modify the behaviour of classes that have already been compiled. In this case you are compiling the Test type. If the aspects are relatively stable, you can separate them into another project and build that into a jar (say trace.jar), you can then modify the AJDT configuration to add the jar to the aspect libraries (from memory, so apologies if it's not accurate, go to the project properties, select the aspectj compiler option, select the aspect libraries/path tab and add your aspect jar). Doing this means that the aspects in the jar will be applied to Test.java on each build.



来源:https://stackoverflow.com/questions/1007841/aspectj-compile-java-source-with-precompiled-aspects

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