Lombok is a popular Java library that simplifies Java application development by reducing boilerplate code and making our codebase clean and easy to understand. It is an annotation-based library that provides several annotations to be used in Java classes to automatically generate the biolerplate codes for getters, setters, constructors, etc. These annotations are processed at compile time.
Some commonly used lombok annotations are the following:
- @Getter and @Setter: These annotations are used to generate getters and setters for fields in Java classes.
- @AllArgsConstructor and @NoArgsConstructor: They generate all arguments and no argument constructor, respectively.
- @ToString: Generates toString method for the member variables.
- @Data: It is used as a combination of @Getter, @Setter, @ToString, @EqualAndHashCode and @RequiredArgsConstructor.
How to resolve the Lombok not generating getter and setter issue?
Sometimes, when we install a new or fresh IDE, such as Eclipse, and we try using the Lombok library, we face issues where the library is not generating the biolerplate code for getter, setter, or any other source code. In order to resolve this issue, along with the fresh installation of the IDE, we need to freshly install the Lombok library.
How to install Lombok in Eclipse?
Step 1: Lombok Jar location
First, we need to go to the lombok jar location. By default, it is present in our user directory, ~.m2\repository\org\projectlombok\lombok\1.18.30.
Step 2: Run Lombok Jar
Once, we reached the lombok jar location. We need to run the lombok jar. We will be using the following command to run the jar:
java -jar lombok-1.18.30.jar
Make sure to use your own jar version.
After we execute the above command, it will open a new window that scans for all the IDEs installed on the system. We need to click on the Install/Update button.
Once the installation is complete, we get the Install successful notification, and our Lombok issue gets resolved.