Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

java - Eclipse Lombok annotations not compiled... Why?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...