Eclipse Lombok annotations not compiled… Why?

浪尽此生 提交于 2019-12-18 06:24:49

问题


I have a problem with my project. It is an Spring CRUD RestFul API that expose services witch are providing Json datas. I use JDK-7, Eclipse-Neon and Maven to code, build and the project is deployed into a JBossEAP 6.4 server. Every thing is working well, the services are responding correctly.

So I decide to add Lombok, to reduce the boiler code and improve the readability of the code. By the way I used Lombok on an another project before and is worked fine.

Here is my problem, after including Lombok : - When I make an ear using Maven (mvn clean install), everything is going well, the project deploy and work perfectly fine. - When the project is built by Eclipse, the Lombok annotations (i.e.:@Data, etc) aren't included into the *.class. Consequently the ear deployed by Eclipse work fine BUT all the entity haven't any getter / setter and so on.

I know Eclipse is correctly configured because I haven't any warning associated to Lombok on my code, the outline view of eclipse show me generated methods.

Does anyone have a idea about this kind of problem?


回答1:


You also must have the lombok plugin installed in Eclipse. (Note that this is something different from lombok being present in the project dependencies; you need both.) Furthermore, the version installed in Eclipse should be the same version that you have in your pom.xml. Otherwise strange compilation issues may occur, like code for some annotations not getting generated in Eclipse but in maven, or vice versa.

Installation instructions for Eclipse can be found here.

Check the "About Eclipse" dialog after the installation and an Eclipse restart. It must contain some text like "Lombok v1.18.3 "Edgy Guinea Pig" is installed.". If that is not the case, the lombok plugin is not installed correctly.

If the installation was not successful, you should try installing lombok to a clean Eclipse installation (even before adding any projects).

Explanation: Eclipse uses its own compiler (different from javac, which maven uses). Therefore, lombok also has to hook into the Eclipse compilation process, and therefore, Eclipse needs that lombok plugin.

Also note that Lombok annotation should never be present in the compiled class file, because the Lombok annotation processor removes them when generating the replacement code.



来源:https://stackoverflow.com/questions/42301333/eclipse-lombok-annotations-not-compiled-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!