无法使 Project Lombok 在 Eclipse 上工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3418865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 19:32:43  来源:igfitidea点击:

Cannot make Project Lombok work on Eclipse

eclipselombok

提问by user310291

I have followed the tutorial here http://projectlombok.org/

我已经按照这里的教程 http://projectlombok.org/

but after adding import and @Datanothing happens.

但是在添加导入后@Data没有任何反应。

Does it work on eclipse helios ?

它适用于日食 helios 吗?

回答by Roel Spilker

You not only have to add lombok.jar to the libraries, but also install it by either double-clicking the lombok jar, or from the command line run java -jar lombok.jar. That will show you a nice installer screen. Select your Eclipse installation and install.

您不仅必须将 lombok.jar 添加到库中,还必须通过双击 lombok jar 或从命令行运行来安装它java -jar lombok.jar。这将向您显示一个不错的安装程序屏幕。选择您的 Eclipse 安装并安装。

Afterwards, you can check if the installer has correctly modified your eclipse.ini:

之后,您可以检查安装程序是否正确修改了您的 eclipse.ini:

-vmargs
...
-javaagent:lombok.jar
-Xbootclasspath/a:lombok.jar

If your Eclipse was already running, you have to Exit Eclipse and start it again. (File/Restart is not enough)

如果您的 Eclipse 已经在运行,您必须退出 Eclipse 并重新启动它。(文件/重启是不够的)

If you are starting Eclipse using a shortcut, make sure that either there are no command line arguments filled in, or manually add -javaagent:lombok.jar -Xbootclasspath/a:lombok.jarsomewhere after -vmargs.

如果您使用快捷方式启动 Eclipse,请确保没有填写命令行参数,或者-javaagent:lombok.jar -Xbootclasspath/a:lombok.jar-vmargs.

Recent editions of Lombok also add a line to the About Eclipse screen. If Lombok is active you can find a line like 'Lombok v0.11.6 "Dashing Kakapo" is installed. http://projectlombok.org/' just above the line of buttons.

Lombok 的最新版本还在 About Eclipse 屏幕上添加了一行。如果 Lombok 处于活动状态,您可以找到类似“Lombok v0.11.6 "Dashing Kakapo" is installed 这样的行。http://projectlombok.org/' 就在按钮行上方。

If for some reason, usually related to customized eclipse builds, you need to use the full path, you can instruct the installer on the command line to do so:

如果由于某种原因,通常与自定义 eclipse 构建相关,您需要使用完整路径,您可以在命令行上指示安装程序这样做:

java -Dlombok.installer.fullpath -jar lombok.jar

java -Dlombok.installer.fullpath -jar lombok.jar

回答by VonC

Did you add

你加了吗

-vmargs
...
-javaagent:lombok.jar
-Xbootclasspath/a:lombok.jar

to your eclipse.ini?

到你的eclipse.ini

Because if you have (and if you have added the lombok.jar to the libraries used by your project), it works just fine with Eclipse Helios:

因为如果你有(并且如果你已经将 lombok.jar 添加到你的项目使用的库中),它在 Eclipse Helios 上工作得很好:

alt text

替代文字



Ian Tegebomentions in the commentsthat:

Ian Tegebo评论中提到:

a simple "restart" was not sufficient to pick up the changed vmargs:
I needed to explicitly exit and then start again.

简单的“重新启动”不足以获取更改后的 vmargs:
我需要明确退出然后重新启动



chrisjleumentions in the comments:

chrisjleu评论中提到:

If you happen to be running a customized Eclipse Helios (3.6+) distribution then you may have to use the full path to lombok.jarin both the vmarguments.
See commit b47e87ffor more details.

如果您碰巧正在运行定制的 Eclipse Helios (3.6+) 发行版,那么您可能必须lombok.jar在两个vm参数中使用完整路径。
有关更多详细信息,请参阅提交 b47e87f

boolean fullPathRequired = IdeFinder.getOS() == EclipseFinder.OS.UNIX || System.getProperty("lombok.installer.fullpath") != null;

回答by Forza

After adding lombok and restarting eclipse or spring tools my project still failed to recognize getters and setters. Red markers everywhere!

添加 lombok 并重新启动 eclipse 或 spring 工具后,我的项目仍然无法识别 getter 和 setter。随处可见的红色标记!

The solution: right-click your project, go to Maven and select Update Project

解决方案:右键单击您的项目,转到 Maven 并选择更新项目

After hours of searching and trying random solution, I find this to be the only solution that worked for me.

经过数小时的搜索和尝试随机解决方案,我发现这是唯一对我有用的解决方案。

enter image description here

在此处输入图片说明

回答by the_D

Please follow the following steps:- If lombok jar has already been added as dependency in eclipse, then go to project's lib folder > Locate Lombok.xx.jar > Right Click on Jar> Run as Java Application> This will launch Lombok screen as below:- enter image description here

请按照以下步骤操作:- 如果 lombok jar 已经在 eclipse 中添加为依赖项,则转到project's lib folder > Locate Lombok.xx.jar > Right Click on Jar> Run as Java Application> This will launch Lombok screen as below:- 在此处输入图片说明

Next, click on "Specify location" > And specify location of "Eclipse.ini" file.(Eclipse neon on Mac osX has it at -> "<Eclipse_installation_path>/jee-neon/Eclipse.app/Contents/Eclipse/Eclipse.ini").

接下来,点击"Specify location" > And specify location of "Eclipse.ini" file.(Eclipse neon on Mac osX has it at -> "<Eclipse_installation_path>/jee-neon/Eclipse.app/Contents/Eclipse/Eclipse.ini")

After this, restart eclipse and Clean build project.

之后,重新启动 eclipse 和 Clean build 项目。

This worked for me.

这对我有用。

回答by Viktor K.

Don't forget to do to Project->Clean in eclipse to make sure that your classes are recompiled.

不要忘记在 Eclipse 中执行 Project->Clean 以确保重新编译您的类。

回答by Jesper Knudsen

I can only make this work if I start the eclipse.exe directly in the eclipse installation folder. If I use a command file setting some initial JAVA_HOME and maven parameters before running the eclipse.exe it does not work and I get compiler errors on the exact same projects

如果我直接在 eclipse 安装文件夹中启动 eclipse.exe,我只能使这项工作。如果我在运行 eclipse.exe 之前使用命令文件设置一些初始 JAVA_HOME 和 maven 参数,则它不起作用,并且在完全相同的项目中出现编译器错误

回答by user1154393

Remenber run lombok.jaras a java app, if your using windows7 open a console(cmd.exe) as adminstrator, and run C:"your java instalation"\ java -jar "lombok directory"\lombok.jarand then lombok ask for yours ides ubication.

记住lombok.jar作为java应用程序运行,如果你使用windows7作为管理员打开一个控制台(cmd.exe),然后运行C:"your java instalation"\ java -jar "lombok directory"\lombok.jar然后lombok询问你的ide ubication。

回答by Dennis

This sometimes does not work if Eclipse is on one of those strange default windows paths (e.g. c:/Program files (86)/Eclipse).

如果 Eclipse 位于那些奇怪的默认窗口路径之一(例如c:/Program files (86)/Eclipse)上,这有时不起作用。

In that case, do as above, then move the lombok jar to a cleaner path without spaces and braces (e.g. c:\lombok\lombok.jar) and modify eclipse.ini accordingly.

在这种情况下,按照上述操作,然后将 lombok jar 移动到没有空格和大括号(例如c:\lombok\lombok.jar)的更干净的路径,并相应地修改 eclipse.ini。

回答by Torque

I ran into this problem due to the missing:

由于缺少以下内容,我遇到了这个问题:

-vmargs -javaagent:lombok.jar -Xbootclasspath/a:lombok.jar

-vmargs -javaagent:lombok.jar -Xbootclasspath/a:lombok.jar

as well. What is not explicitly said neither here nor in the Lombok popup message, and was not obvious to me as someone who never before had to fiddle with the eclipse.ini, is that you are NOT supposed to add that line, but instead add the last two parts of that line after the first part, which is already in the eclipse.ini file. To better illustrate, the end of the file should look something like this (bold is what matters for Lombok, the rest might be different for you):

以及。在这里和 Lombok 弹出消息中都没有明确说明,作为以前从未摆弄过 eclipse.ini 的人,对我来说并不明显的是,您不应该添加该行,而是添加最后一行该行的第一部分之后的两部分,该部分已经在 eclipse.ini 文件中。为了更好地说明,文件的结尾应该是这样的(粗体对 Lombok 来说很重要,其余的对你来说可能会有所不同):

-vm
C:/Program Files/Java/jdk1.7.0_02/bin
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx384m
-javaagent:lombok.jar
-Xbootclasspath/a:lombok.jar

-vm
C:/Program Files/Java/jdk1.7.0_02/bin
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx384m
-javaagent:lombok.jar
-Xbootclasspath/a:lombok.jar

回答by Rasik

If you are using windows xp and eclipse juno then it should be like this in order

如果您使用的是 windows xp 和 eclipse juno 那么它应该是这样的

-vmargs
-Dosgi.requiredJavaVersion=1.5
-Dhelp.lucene.tokenizer=standard
-javaagent:lombok.jar
-Xbootclasspath/a:lombok.jar
-Xms40m
-Xmx512m