Aspectj Cookbook
This chapter contains recipes for getting started in developing your own aspect-oriented code using AspectJ. Beginning with the task of getting a build environment set up and moving through the different types of builds and targets, this chapter provides a tutorial in the basics of AspectJ development. With an understanding of the fundamental concepts in aspect orientation, this chapter first covers getting your fingers dirty using AspectJ's development environment. At the core of AspectJ is its build support for weaving aspects into your Java code. This is currently done using a compiler, ajc, that interacts with the existing Java compiler, javac. Working within the constraints of the Java compilation process ensures that your aspect-oriented programs produce standard Java classes that can be run by any Java Virtual Machine (JVM). ajc simply automates the mapping of your aspects onto your Java classes. The ajc tool is used for compile-time weaving of aspects either from the command line or within an IDE or other build tool, but there is also an alternative weaving method supported in AspectJ, load-time weaving. As its title suggests, load-time weaving supports the weaving of aspects into your application at the time when the Java class loader is loading the application into the JVM. This is a fairly new feature of AspectJ and is briefly described in this chapter with the caveat that the current methods by which load-time weaving is achieved using AspectJ may change in the future as this facility matures. Once you have got the hang of using the ajc command-line compiler then it's time to move on to installing and using some of the capabilities available to the AspectJ developer within the Eclipse development environment. These include how to set up an Eclipse project with an AspectJ Nature using the new project creation wizards and using Eclipse to vary the aspects that are actually built into a single project using AspectJ build configuration files. Finally, AspectJ project housekeeping tasks such as documentation generation from AspectJ code and building using Ant are covered in this chapter demonstrating just how rich, powerful, and supported the AspectJ development tools are. |