Using the AspectJ Compiler (ajc)
ajc settings specified at the project level can be fine-tuned at the level of individual modules. AspectJ facets associated with the modules are used for that purpose.
ajc is not bundled with IntelliJ IDEA and should be downloaded separately.
ajc is available as part of the AspectJ distribution which you can download from the AspectJ website.
- Optimizing compilation performance: Using ajc in combination with javac
- Controlling the ajc aspectpath
- Selecting ajc as the project compiler and specifying its settings
- Fine-tuning the use of ajc at a module level
Optimizing compilation performance: Using ajc in combination with javac
IntelliJ IDEA lets you use
ajc in combination with
javac without the need to switch the compilers in the IDE settings.
If you want
javac to be also used, turn on the Delegate to Javac option. If this option in on, the modules without aspects are compiled with
javac (which is, generally, faster), and the modules that contain aspects are compiled with
ajc. (If this option is off,
ajc is used for all the modules in your project.)
You can fine-tune the distribution of tasks between the compilers (
javac) at the level of individual modules. For modules that contain aspects only in the form of
@Aspect-annotated Java classes (in
.java files), you can specify that
ajc should be used only for post-compile weaving. If you do so,
javac will be used to compile all the source files, and then
ajc will be applied to the compiled class files for weaving. As a result, the overall process (compilation + weaving), will take less time.
Provided that the Delegate to Javac option is on, the post-compile weaving mode for
ajc is enabled by turning on the corresponding option in an AspectJ facet associated with a module.
Note that you shouldn't turn on this option for modules that contain code-style aspects (ones defined in
Controlling the ajc aspectpath
aspectpath may be set automatically as a result of importing an appropriately configured Maven project into IntelliJ IDEA.
Selecting ajc as the project compiler and specifying its settings
- Open the Settings dialog (e.g. Ctrl+Alt+S).
- In the left-hand part of the dialog, in the search box, type
compiler. Then, select Java Compiler in the pane below the search box.
- On the Compiler > Java Compiler page that opens in the right-hand part of the dialog:
- Select Ajc from the Use compiler list.
- If necessary, specify the bytecode versions. (Roughly, these are the minimum target JVM versions.)
- Specify the path to the compiler in the Path to Ajc compiler field.
You can type the path in the field, or click and select the necessary file in the corresponding dialog.
(The file that you want is
aspectjtools.jarwhich is located in
<AspectJ installation directory>\lib.)
- If necessary, specify the command-line options to be passed to the compiler in the Command line parameters field.
You can type the parameters right in the field, or click to open the Command line parameters dialog where the text entry area is larger.
- Click Test to check if the specified settings are correct.
- If you want to use
javacto compile the modules that contain no aspects, select the Delegate to Javac checkbox.
Note that the distribution of tasks between
javaccan be fine-tuned at the level of individual modules.
- Click OK in the Settings dialog.
Fine-tuning the use of ajc at a module level
To be able to fine-tune the use of
ajc at a module level, you should add an AspectJ facet to corresponding module or modules.
Once you've done that, you can specify that
ajc should be used only for post-compile weaving. You can also specify the
aspectpath for the module.
- Add an AspectJ facet to the module of interest. For corresponding instructions, see Add support for frameworks and technologies.
- On the page that opens in the right-hand part of the Project Structure dialog, under Compiler, specify the settings as necessary (see below).
- If you want to use
ajconly to weave the compiled class files (the source code in this case is compiled with
javac), select the Post-compile weave mode checkbox.
IMPORTANT: Don't select this checkbox if the module contains
- To form the
aspectpathfor the module:
- Use (Alt+Insert) to add libraries and other modules. Select the necessary libraries and modules in the dialog that opens. (To choose from, dependencies of the module are suggested.)
- Use (Alt+Delete) to remove the selected items from the list.
- Use (Alt+Up) to move the selected item one line up in the list.
- Use (Alt+Down) to move the selected item one line down in the list.
- Click OK in the Project Structure dialog.