IntelliJ IDEA 2016.3 Help

Using the AspectJ Compiler (ajc)

This feature is supported in Ultimate edition only.

By default, IntelliJ IDEA uses the javac compiler. To use the AspectJ compiler ajc (instead of or in combination with javac), you should make changes to corresponding IDE settings.

The 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.

Note that 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

IntelliJ IDEA lets you use ajc in combination with javac without the need to switch the compilers in the IDE settings.

First of all, you should select ajc as your project compiler (the Use compiler field on the Java Compiler page).

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 (ajc and 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 .aj files).

Controlling the ajc aspectpath

You can control the ajc aspectpath option separately for each of your modules, see Fine-tuning the use of ajc at a module level.

The module 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

  1. Open the Settings dialog (e.g. Ctrl+Alt+S).
  2. 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.
  3. On the Compiler > Java Compiler page that opens in the right-hand part of the dialog:
    1. Select Ajc from the Use compiler list.
    2. If necessary, specify the bytecode versions. (Roughly, these are the minimum target JVM versions.)
    3. Specify the path to the compiler in the Path to Ajc compiler field.

      You can type the path in the field, or click /help/img/idea/2016.3/browseButton.png and select the necessary file in the corresponding dialog.

      (The file that you want is aspectjtools.jar which is located in <AspectJ installation directory>\lib.)

    4. 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 /help/img/idea/2016.3/shift-enter-button.png to open the Command line parameters dialog where the text entry area is larger.

    5. Click Test to check if the specified settings are correct.
    6. If you want to use javac to compile the modules that contain no aspects, select the Delegate to Javac check box.

      Note that the distribution of tasks between ajc and javac can be fine-tuned at the level of individual modules.

  4. 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.

  1. Add an AspectJ facet to the module of interest. For corresponding instructions, see Adding support for a framework.
  2. On the page that opens in the right-hand part of the Project Structure dialog, under Compiler, specify the settings as necessary (see below).
  3. If you want to use ajc only to weave the compiled class files (the source code in this case is compiled with javac), select the Post-compile weave mode check box.

    IMPORTANT: Don't select this check box if the module contains .aj files.

  4. To form the aspectpath for the module:
    • Use /help/img/idea/2016.3/new.png (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 /help/img/idea/2016.3/delete.png (Alt+Delete) to remove the selected items from the list.
    • Use /help/img/idea/2016.3/arrowUp.png (Alt+Up) to move the selected item one line up in the list.
    • Use /help/img/idea/2016.3/arrowDown.png (Alt+Down) to move the selected item one line down in the list.
  5. Click OK in the Project Structure dialog.

See Also

Last modified: 7 December 2016