本文介绍了龙虾不生成getter / setter(用Luna或命令行编译)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次试图lombok。我试图尽可能地遵循指导,但是当我查看我编译的类(使用反编译器)时,他们没有任何生成的getter或setter。



我的安装步骤:


  1. 下载lombok 1.14.8并运行java -jar lombok.jar。它向日食添加了lombok。重新启动的Eclipse(也可以清理工作区)。如果我查看我的关于Eclipse页面,我会看到:



    Lombok v1.14.8分支眼镜蛇已安装。


  2. 将lombok添加到我的pom.xml中:

     <依赖关系> 
    < groupId> org.projectlombok< / groupId>
    < artifactId> lombok< / artifactId>
    < scope>已提供< / scope>
    < version> 1.14.8< / version>
    < / dependency>


  3. Maven->更新项目。项目 - >清洁


我的Lombok的java类:

  import lombok.Getter; 
import lombok.Setter;

public class用户扩展BaseCouchDbDocument {

public User(){
// TODO自动生成的构造函数存根
}

@Getter @Setter
private String name;
}

当在Eclipse中使用代码完成时,我看到 User.getName() User.setName()出现。但是,如果我尝试使用getter或setter,我得到一个编译时错误,不存在这样的方法。当我查看生成的.class文件时,我只看到以下内容:

  public class User extends BaseCouchDbDocument 
{
private String name;
}

同样,如果我运行 mvn compile 从命令行,我得到相同的类输出。



我觉得奇怪的是, @Getter @Setter 注释被删除,这意味着我的文件有一些处理。但是没有生成getter / setter。



我做错了什么?我在Mac上使用Java 7。

解决方案

发布后,我遇到了一个错误报告,表示它是AspectJ的问题。



的确,我正在使用AspectJ与我的项目,这是导致与龙目岛的冲突。删除AspectJ现在显示正确生成的设置器/ getter。



这显然不会解决问题,但至少指出我的方向正确。我来跟踪此具体问题。



希望这可以帮助未来的其他人。


I'm trying to lombok for the first time. I tried to follow directions as best as possible, but when I look at my compiled classes (using a decompiler) they do not have any of the generated getters or setters.

My installation steps:

  1. Downloaded lombok 1.14.8 and ran java -jar lombok.jar. It added lombok to eclipse. Restarted Eclipse (-clean the workspace too). If I check my About Eclipse page, I see:

    "Lombok v1.14.8 "Branching Cobra" is installed. http://projectlombok.org/"

  2. Added lombok to my pom.xml:

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
        <version>1.14.8</version>
    </dependency>
    

  3. Maven->Update Project. Project->Clean

My Lombok'ed java class:

import lombok.Getter;
import lombok.Setter;

public class User extends BaseCouchDbDocument {

    public User() {
        // TODO Auto-generated constructor stub
    }

    @Getter @Setter
    private String name;
}

When using the code completion in Eclipse, I see User.getName() and User.setName() appear. However, if I try to use the getters or setters, I get a compile time error that no such method exists. When I look at the generated .class file, I only see the following:

public class User extends BaseCouchDbDocument
{
  private String name;
}

Similarly, if I run mvn compile from the command line, I get the same class output.

What I find odd is that the @Getter and @Setter annotations are removed, implying that there is some processing occurring on my files. But the getters/setters aren't being generated.

Am I doing something wrong? I'm using Java 7 on a Mac.

解决方案

After posting this, I ran across a bug report that indicated it was a problem with AspectJ.

Indeed, I am using AspectJ with my project, and it is causing conflicts with Lombok. Removing AspectJ now shows properly generated setters/getters.

This obviously does not "resolve" the issue, but at least points me in the right direction. I created another issue here to track this specific problem.

Hopefully this can help someone else in the future as well.

这篇关于龙虾不生成getter / setter(用Luna或命令行编译)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:31