Recipe2.1.Installing AspectJ


Recipe 2.1. Installing AspectJ

Problem

You want to set up an AspectJ build environment.

Solution

At its simplest, AspectJ installation is a four-step process:

  1. Download the AspectJ tools from http://www.aspectj.org.

  2. Install the downloaded JAR files by double-clicking on them. This will create an aspectj1.2 directory on your machine.

  3. Test your environment with the following command:

    > ajc AspectJ Compiler         Usage: <options> <source file | @argfile>.. AspectJ-specific options:         ... Listed compiler options 1 fail|abort

  4. Don't worry about the 1 fail | abort message here; if you get the output shown above, then the AspectJ tools have been successfully installed and located and are available for use.

  5. Copy aspectj1.2/lib/aspectjrt.jar to a library directory of your JRE. Typical locations for this directory are %JAVA_HOME%\jre\lib\ext for Windows and /Library/Java/Extensions for Mac OS X.

Discussion

The first step in preparing to develop using aspects is to download the appropriate support tools for your environment. In the case of AspectJ, this involves downloading the AspectJ libraries and tools. These tools can be obtained by accessing http://www.aspectj.org and following the links to Downloads.

Once the appropriate AspectJ development kits have been downloaded, they can be installed by double-clicking on the downloaded .jar file. After installation, you will find a directory named aspectj1.2 (if the default installation options were accepted).

The AspectJ installer specifies some important instructions at the end of the installation process. These instructions include setting up your search path so that the AspectJ tools are available from the command line and adding the AspectJ Java libraries to your Java classpath. It's worth taking care to follow those instructions to make things as easy as possible when setting up your AspectJ development environment.


In the %MY_HOME_DIRECTORY%/aspectj1.2/bin directory, you will see that AspectJ comes with three tools:


ajc (ajc.bat on Windows)

The AspectJ compiler.


ajbrowser (ajbrowser.bat on Windows)

The AspectJ tools test environment that can be used to develop AspectJ projects.


ajdoc (ajdoc.bat on Windows)

The AspectJ documentation tool.

ajc and ajdoc are the AspectJ equivalents of javac and javadoc from the standard Java Development Kit. In fact, both of the AspectJ tools use the standard Java tools to do their job, providing enhancements to cater to the additional AspectJ syntax and structure.


It is worth taking a look around the AspectJ installation, particularly within the %MY_HOME_DIRECTORY/aspectj1.2/doc/index.html directory as a wealth of support documentation is provided, including:


%MY_HOME_DIRECTORY%/aspectj1.2/doc/progguide/

The AspectJ Programming Guide for all users of AspectJ.


%MY_HOME_DIRECTORY%/aspectj1.2/doc/devguide/

The AspectJ Developers Guide for anyone who wants to build and contribute to AspectJ.


%MY_HOME_DIRECTORY%/aspectj1.2/doc/api/

The AspectJ runtime API, also summarized in the Appendix A.


%MY_HOME_DIRECTORY%/aspectj1.2/examples/

A collection of useful and interesting AspectJ coding examples to get you started.

You have now set up the environment on your machine for development of aspect-oriented software using AspectJ.

It's a good idea to check the AspectJ web site regularly at http://www.eclipse.org/aspectj for information on the newest updates to the toolset. You can also register yourself on the AspectJ users mailing list to get notifications of changes to the tools and news on how the AspectJ tools are being employed throughout the software industry.

A set of easy installers to get you up and running as quickly and simply as possible using AspectJ are available at http://www.aspectjcookbook.com. These installers install and configure an entire AspectJ build environment including AspectJ, the Eclipse IDE, and the AspectJ plug-in for Eclipse. While the versions contained in these installers are not guaranteed to be the latest that are available from the individual sources at www.eclipse.org, www.eclipse.org/aspectj, and www.eclipse.org/ajdt, they do provide everything you need in an easy to install package.


See Also

The next stage in getting familiar with AspectJ is to start coding your first aspect as shown in Recipe 2.2; the ajdoc tool is examined in some detail in Recipe 2.6; the AspectJ Development Environment Guide available at http://www.eclipse.org/aspectj provides more details on the runtime options and flags that the AspectJ tools support; the other recipes in this chapter show how to take things further by compiling more complex AspectJ projects within Eclipse and using the Ant[1] build tool.

[1] Ant, which stands for Another Neato Tool, is a pure Java build tool that is controlled using XML build configuration files, and offers a nice alternative to the more traditional and cryptic Make files.



AspectJ Cookbook
Aspectj Cookbook
ISBN: 0596006543
EAN: 2147483647
Year: 2006
Pages: 203
Authors: Russ Miles

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net