简体   繁体   中英

How to migrate an Eclipse AspectJ project to IntelliJ IDEA

At my company, we are currently working with Eclipse for our Java projects. As me and some other coworkers would rather use IntelliJ, we took a crack at migrating our projects and failed at getting AspectJ to work.

We are using Java 7 though the projects are written in Java 6 compatility. Before trying it out we updated to the most recent version of IDEA (14.03). The AspectJ version is 1.7.3.

Here are the steps we took:

  • import the project and dependencies into IntelliJ
  • download and install AspectJ
  • Under Settings -> Java Compiler: Use ajc compiler, delegate to javac (path to aspectjtools.jar is correct as the test button indicates)
  • Add AspectJ libs to Global Libraries (aspectjrt.jar, aspectjtools.jar, aspectjweaver.jar, and org.aspectj.matcher.jar)
  • Create AspectJ facet for the one module that is using AspectJ, leave all settings as is (no aspect path defined)
  • Add aspectjrt to project libraries
  • rebuild, make etc.

LogContext is just an empty interface. Classes that want a logger appended implement this interface.

This method is injected with AspectJ. Unfortunately I am not an expert with this and the guy who implemented it left the company, so I am stuck.

In order to check general functionality, we implemented a tiny project from scratch with just three classes with the same settings as above:

public interface LogContext {}
public aspect LogContextAspect {
    public void LogContext.log() {
        System.out.println("Log!");
    }
}
public class Aspect implements LogContext {
    public static void main(String[] args) {
        Aspect aspect = new Aspect();
        aspect.log();
    }
}

The code actually executes fine and prints out the "Log!" message, but on make I get the following error:

Error:(4, 0) ajc: The type Aspect must implement the inherited abstract method LogContext.log()

What are we missing here? In order to migrate our projects, we need AspectJ to work. The whole system is built with Java 6 compatibility but runs on Java 7.

Thanks for your help!

Sascha

I tried with IDEA 14.1.1 Ultimate and it works nicely, even though AspectJ support in IDEA is generally not as advanced as in Eclipse, even though all in all IDEA to me is superior. But for AspectJ I often use Eclipse.

I think it would be a good idea to "mavenise" your project. This way it would work in Eclipse and IDEA. In IDEA activate auto import for Maven changes to let Maven be the leading system and IDEA just follow its settings. This works well for my AspectJ projects. But in this case I set up your example manually (no Maven). After a few steps it works now. Along the way I did not see the error message you mentioned.

Edit: I use AspectJ 1.8.5, if that makes any difference.

Edit 2: I have tried with both compiler and runtime manually set to 1.7.3, it still works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM