ajc

Name

ajc — compile AspectJ and Java language source files

Synopsis

ajc [Options] [file... | @file... | -arglist file...]

Description

The command ajc compiles AspectJ and Java language source files into class files. Options and files may be specified directly on the command line, or indirectly by naming a file which contains them.

The arguments after the options specify the file(s) to compile. Files may be listed directly on the command line, or listed in a file. The @file and -argfile file forms are equivalent, and are interpreted as meaning all the files listed in the specified file. Each line in these files should contain one option or filename. Comments, as in Java, start with // and extend to the end of the line.

Options

-verbose

Output messages about what ajc is doing

-version

Print the version of ajc

-nocomments

Don't generate any comments into the woven code. Only relevant with -preprocess mode.

-emacssym

Generate symbols used by AJDE for Emacs

-nosymbols

Don't generate .ajsym or .ajsline files

-usejavac

Use javac to generate .class files

-preprocess

Don't try to generate any .class files. Generate regular Java code into workingdir

-workingdir Directory

Specify where to place intermediate .java files Directory defaults to ./ajworkingdir. Only relevant with -usejavac or -preprocess modes.

-O

Optimize; may hinder debugging or enlarge class files

-deprecation

Output source locations where deprecated APIs are used

-d Directory

Specify where to place generated .class files Directory defaults to the current working dir

-classpath Path

Specify where to find user class files

-bootclasspath Path

Override location of bootstrap class files

-extdirs Path

Override location of installed extensions

-argfile File

the file is a line-delimited list of arguments these arguments are inserted into the argument list

-encoding

Specify character encoding used by source files

-lenient

Be extra-lenient in interpreting the java specification This allows some statements that some compilers consider errors.

-strict

Be extra-strict in interpreting the java specification This signals errors for some statements that many compilers don't catch.

File names

ajc accepts source files with either the .java extension or the .aj extension. We normally use .java for all of our files in an AspectJ system -- files that contain aspects as well as files that contain classes. However, if you have a need to mechanically distinguish files that use AspectJ's additional functionality from those that are pure Java we recommend using the .aj extension for those files.

We'd like to discourage other means of mechanical distinction such as naming conventions or sub-packages in favor of the .aj extension.

  • Filename conventions are hard to enforce and lead to awkward names for your aspects. Instead of TracingAspect.java we recommend using Tracing.aj (or just Tracing.java) instead.
  • Sub-packages move aspects out of their natural place in a system and can create an artificial need for privileged aspects. Instead of adding a sub-package like aspects we recommend using the .aj extension and including these files in your existing packages instead.

Compatibility

AspectJ is a compatible extension to the Java programming language. The AspectJ compiler adheres to the The Java Language Specfication, Second Edition and to the The Java Virtual Machine Specification, Second Edition and runs on any Java 2 compatible platform. The code it generates runs on any Java 1.1 or later compatible platform.

Examples

Example 1. A simple example

Compile two files:

        ajc HelloWorld.java Trace.java
        

The AspectJ compiler API

The AspectJ compiler is implemented completely in Java and can be called as a Java class. The only interface that should be considered public is the method org.aspectj.tools.ajc.Main.main(String[] args) where args are the standard ajc command line arguments. This means that an alternative way to run the compiler is

java org.aspectj.tools.ajc.Main [option...] [file...]

You must additionally include tools.jar from your Java developer's kit in your classpath.