简体   繁体   English

如何将Eclipse AspectJ项目迁移到IntelliJ IDEA

[英]How to migrate an Eclipse AspectJ project to IntelliJ IDEA

At my company, we are currently working with Eclipse for our Java projects. 在我的公司,我们目前正在使用Eclipse进行Java项目。 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. 由于我和其他一些同事宁愿使用IntelliJ,我们在迁移项目时遇到了麻烦,但未能使AspectJ工作。

We are using Java 7 though the projects are written in Java 6 compatility. 虽然这些项目是用Java 6编写的,但我们使用的是Java 7。 Before trying it out we updated to the most recent version of IDEA (14.03). 在尝试之前,我们更新了最新版本的IDEA(14.03)。 The AspectJ version is 1.7.3. AspectJ版本是1.7.3。

Here are the steps we took: 以下是我们采取的步骤:

  • import the project and dependencies into IntelliJ 将项目和依赖项导入IntelliJ
  • download and install AspectJ 下载并安装AspectJ
  • Under Settings -> Java Compiler: Use ajc compiler, delegate to javac (path to aspectjtools.jar is correct as the test button indicates) 在设置 - > Java编译器:使用ajc编译器,委托给javac(aspectjtools.jar的路径是正确的,如测试按钮所示)
  • Add AspectJ libs to Global Libraries (aspectjrt.jar, aspectjtools.jar, aspectjweaver.jar, and org.aspectj.matcher.jar) 将AspectJ库添加到全局库(aspectjrt.jar,aspectjtools.jar,aspectjweaver.jar和org.aspectj.matcher.jar)
  • Create AspectJ facet for the one module that is using AspectJ, leave all settings as is (no aspect path defined) 为使用AspectJ的一个模块创建AspectJ方面,保留所有设置(未定义方面路径)
  • Add aspectjrt to project libraries 将aspectjrt添加到项目库
  • rebuild, make etc. 重建,制作等

LogContext is just an empty interface. LogContext只是一个空接口。 Classes that want a logger appended implement this interface. 想要附加记录器的类实现此接口。

This method is injected with AspectJ. 使用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!" 代码实际执行正常并打印出“Log!” message, but on make I get the following error: 消息,但在make我得到以下错误:

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. 为了迁移我们的项目,我们需要AspectJ才能工作。 The whole system is built with Java 6 compatibility but runs on Java 7. 整个系统使用Java 6兼容性构建,但在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. 我尝试使用IDEA 14.1.1 Ultimate并且它工作得很好,尽管IDEA中的AspectJ支持通常不像Eclipse中那样先进,尽管对我来说所有IDEA都优越。 But for AspectJ I often use Eclipse. 但对于AspectJ,我经常使用Eclipse。

I think it would be a good idea to "mavenise" your project. 我认为对你的项目进行“mavenise”是个好主意。 This way it would work in Eclipse and IDEA. 这样它就可以在Eclipse和IDEA中使用。 In IDEA activate auto import for Maven changes to let Maven be the leading system and IDEA just follow its settings. 在IDEA激活Maven更改的自动导入,让Maven成为领先的系统,IDEA只需遵循其设置。 This works well for my AspectJ projects. 这适用于我的AspectJ项目。 But in this case I set up your example manually (no Maven). 但在这种情况下,我手动设置你的例子(没有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. 编辑:我使用AspectJ 1.8.5,如果这有任何区别。

Edit 2: I have tried with both compiler and runtime manually set to 1.7.3, it still works. 编辑2:我已尝试将编译器和运行时手动设置为1.7.3,它仍然有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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