Since I’ve been futzing around with both AspectJ and JBoss AOP, I thought I’d put some notes together about the differences between the two. This is the first in a multipart series that will compare the two leading AOP implementations, AspectJ 5 and JBoss AOP 1.3.x. AspectWerkz is not compared here since AspectJ 5 is the result of the merger between the AspectJ and the AspectWerkz projects. The Spring Framework was also left out here for the following reasons:
- It is not a full-blown AOP implementation
- It works quite nicely with AspectJ
- Spring 2.0 will make heavier use of AspectJ 5
Since AspectJ and the Spring Framework are complimentary projects, there is no need to compare the two.
With that out of the way, the first part of this series will focus on the development tools for both AOP platforms. These are:
- AJDT 1.3.0 on Eclipse 3.1.1
- JBoss IDE 1.5RC2 on Eclipse 3.1.1
At the time of this writing, the JBoss AOP plugin is only in its second RC release and supports JBoss AOP 1.1 while the current release of JBoss AOP is 1.3.4. One of the key differences between JBoss AOP and AspectJ 5 is that AspectJ is a language extension and requires a bit more ramp-up. In contrast, aspects created with JBoss AOP can be written in plain Java and users only needed to learn a new API. The JBoss folks always make sure to make this point clear and use it as a means to show how much easier it is to use the JBoss AOP framework. With the release of AspectJ 5 however, you can write aspects using the @AspectJ annotations. This development style is pretty much how things got done using AspectWerkz with some changes. So if you’re not up to learning a set of language extensions, you can write your AspectJ aspects using annotated Java classes, much like JBoss AOP.
Both AJDT and JBoss IDE offer some very nice productivity features that make working with advised classes much easier. Both plugins will place advice markers next to the classes, methods, and fields, which are being advised. However, it is how these two plugins do their jobs are what sets them apart.
JBoss AOP allows developers to define pointcuts in both an XML file or use Java 5 annotation. When you define your pointcuts using XML, the IDE will present the advice markers on classes where the advice has been applied. Unfortunately, if you choose to develop you aspects using Java 5 annotations, the IDE plugin becomes nearly useless. Apparently, JBoss IDE only works with XML based point cuts. This is a shame really because annotated aspect development is quite nice since your pointcuts reside in the aspect that is using them. Another area where JBoss IDE falls short is with mixins. A mixin allows you have a class implement an interface. Mixins can make use of an introduction, which enables you to provide an implementation for the mixin. Regardless of what development style you choose, JBoss IDE will not display any advice markers to indicate that a particular class is making use of a mixin or introduction. This is too bad really because it can be difficult sometimes to trace why a pointcut that would apply a mixin is not being applied.
AJDT on the other hand excels at showing you what is being advised and where. If you choose to develop your aspects using the AspectJ language, your pointcuts are treated as keywords and you get full syntax checking. This is incredibly helpful as some pointcuts are difficult write without some assistance. Things get even better once you create your advice; you (almost) immediately see markers on classes where the advice has been applied. AspectJ supports inter-type declarations, which are similar to introductions in JBoss AOP. But unlike JBoss IDE, AJDT will show you that a particular class has gained new functionality as the result of an inter-type declaration. But not only does AJDT support advice highlighting with code-style development, annotation style development is also fully supported. Supported so well that syntax checking (no highlighting though) is available as you type. So no matter what style you choose, you’ll be able to see where your advice is being applied and if it’s valid prior to compile time. This is what really sets the AspectJ development tools apart from the JBoss AOP tools.
However, AJDT is still far from perfect and the plugin doesn’t always function as seamlessly as it could. Since AspectJ is a language extension, there are some pretty major annoyances you’ll find with AJDT within Eclipse. Chief among them is refactoring. Whenever you refactor a class that is referenced by an aspect, the import statement is usually not updated in the aspect and you’ll have to that manually. I say usually because sometimes it does work. Additionally, I have not been successful at being able to rename an aspect using the refactor command. The last two items on my list are “organize imports” and auto complete. These work most of the time, but not all of the time. The organize imports option won’t work if you are using inter-type declarations.
Aspects that are created using the annotation development style aren’t hindered by these problems. Again, since you’re working with annotated Java classes here, organize imports and refactoring work as usual. As you may have guessed, JBoss IDE also does not have any issues with imports and refactoring since you’re dealing with plain old Java here as well. However, when it comes to updating your pointcuts in either JBoss AOP or AspectJ, you’ll have to do this manually.
The short story is that they both suck . From what I can tell, these plugins need to fully compile and weave the aspect into the byte code before it can place the advice markers on advised classes. Which is all fine and good but when you have a project with 500 or more classes, the “Building Workspace” operation blocks user activity and it consumes much more CPU than the usual Eclipse compiler. I worked with a 500+ class project with JBoss IDE and found performance to be so bad on a 2Ghz P4 and 1GB or RAM that I ditched the AOP nature altogether. It was actually faster to create a plain Java project and execute the aspect using loadtime weaving using javaagent.
AspectJ is a similar story. Although the compilation is somewhat faster than JBoss, it consumes a hell of a lot more memory. It’s not unusual to see Eclipse’ heap to grow beyond 512 megabytes when using a project with 1000+ java classes and a single aspect.
So far these IDEs plugins are indeed handy to anyone working with AOP. However, with JBoss in release candidate stage and AJDT in its final release, one might expect something a bit more full-featured or something that actually feels complete. But unfortunately, neither feels like a finished product. But worst of all is the performance of these two plugins. My personal opinion is that using the JBoss IDE plugin for JBoss AOP development is pretty much useless. You’re better off using load-time weaving to unit test your aspects. JBoss IDE doesn’t offer enough for you to bother with the performance hit you’ll take using the tools.
If you’re planning on using AspectJ, AJDT will get you pretty far. I have found it to be the more useful of the two plugins offering the most features for both code and annotated development styles. As your project grows in size, you’ll start to reach its performance limits rather quickly.