简体   繁体   English

Eclipse 报告“该字段的值未使用”警告,即使 Lombok 启用

[英]Eclipse reporting "the value of the field is not used" warning even though Lombok enable

I have 2 classes in a Eclipse project.我在 Eclipse 项目中有 2 个课程。

package com.example;

import lombok.Getter;
import lombok.experimental.Accessors;

@Accessors(fluent = true)
@Getter
public class MyBean {
    private String value = "aaa";
}
package com.example;

public class MyClass {
    public static void main() {
        System.out.println(new MyBean().value());
    }
}

After building, Eclips reports "the value of the field value is not used" for MyBean class and "The method value() is undefined for the type MyClass" even though Eclipse's content assist shows MyBean#value() method, there are no warnings before building, and compilation, execution both are finished successfully.构建后,Eclips 报告MyBean class "the value of the field value is not used""The method value() is undefined for the type MyClass"即使 Eclipse 的内容辅助显示MyBean#value()方法,也没有警告在构建和编译之前,执行都已成功完成。 So I guess Lombok works properly and the problem is Eclipse doesn't recognize Lombok.所以我猜 Lombok 工作正常,问题是 Eclipse 无法识别 Lombok。

Here are what I tried and found.这是我尝试和发现的。

  • attaching lombok.jar to Eclipse and checking eclipse.ini将 lombok.jar 附加到 Eclipse 并检查 eclipse.ini
  • cleaning and rebuild the project清理和重建项目
  • removing Lombok dependency from maven local repository then reinstall从 maven 本地存储库中删除 Lombok 依赖项,然后重新安装
  • the problems only occur in this project.问题只发生在这个项目中。 Eclipse handles other projects with lombok properly (and all projects belong in the same workspace). Eclipse 用 lombok 正确处理其他项目(并且所有项目都属于同一个工作区)。
  • I cannot reproduce these problems in other projects.我无法在其他项目中重现这些问题。

Any ideas?有任何想法吗?

Finally, the problems are solved by just creating new project and moving all sources and resources to it.最后,只需创建新项目并将所有资源和资源移至该项目即可解决问题。 It seems that Eclipse's project configurations were broken I don't know why.似乎Eclipse的项目配置被破坏了我不知道为什么。

I install lombok on eclipse(java -jar lombokxxxx.jar) and the problem disapear.我在 eclipse(java -jar lombokxxxx.jar) 上安装了 lombok 并且问题消失了。

Lombok API Configuration龙目岛 API 配置

Note: Lombok version may change.注意:龙目岛版本可能会更改。 Present we are using 1.18.24目前我们正在使用 1.18.24

  1. Goto -> C:\Users\Udaykiran.Pulipati.m2\repository\org\projectlombok\lombok\1.18.24转到-> C:\Users\Udaykiran.Pulipati.m2\repository\org\projectlombok\lombok\1.18.24
  2. A Lombok configuration window will open > Click on Specify location button Lombok configuration window将打开 > 单击Specify location按钮
  3. Select eclipse.exe root folder where it is located(installed) Select eclipse.exe 所在根文件夹(已安装)
  4. Selecting eclipse.exe root folder > D:\eclipse\jee-2021-06\eclipse选择 eclipse.exe 根文件夹 > D:\eclipse\jee-2021-06\eclipse
  5. Click on Install / Update button in Lombok configuration window单击Lombok configuration window中的Install / Update按钮
  6. Click on Quite Installer点击相当安装程序
  7. Restart Eclipse IDE重启 Eclipse IDE

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

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