concept aspect library in category aspectj

appears as: n aspect library, Aspect libraries, spect libraries, aspect library
AspectJ in Action, Second Edition

This is an excerpt from Manning's book AspectJ in Action, Second Edition.

Figure 8.3. Creating an aspect library involves using –outjar or explicitly using the jar tool. When you use the library, you need the –aspectspath and –inpath options. The output of the system can be multiple class files or a jar file, depending on how you use the –outjar option.

Aspect libraries often contain abstract aspects. You must define concrete subaspects for those aspects to be woven in. Although you can always use code to define subaspects and use the <aspect> elements as discussed in the earlier section, an easier solution is to define concrete aspects using the <concrete-aspect> element. Listing 8.2 shows an example of a concrete aspect defined using AspectJ’s XML syntax by providing a definition for the abstract pointcut in the base aspect.

Because profiling is a reusable functionality, you want to create an aspect library out of it so that you can weave it into any application that needs that functionality.

Creating an aspect library

The mechanics of creating an aspect library differ from source code build-time weaving only in that you don’t pass the classes to be woven to the iajc task. Note that if you use the @AspectJ syntax to develop a library, you can use javac to compile the aspects (optionally, you can package using the jar task). The Ant file in listing B.2 assumes that the profiling aspect is in a separate project (along with any support classes).

Listing B.2. Creating an aspect library using Ant
<project name="Aspect Library" default="compile"> ... unchanged since B.1 <target name="compile"> <mkdir dir="dist"/> <iajc source="1.5" classpathref="project.class.path" outjar="dist/profiling.jar"> <sourceroots> <pathelement location="src/main/java"/> </sourceroots> </iajc> </target> </project>