How to Use Lombok in Java Project and Eclipse


In this article, we will discuss how to use Lombok in Java maven project and also we will discuss how to set up or install Lombok in Eclipse IDE.

Lombok is a library used for reducing the boilerplate code from Java source code.

Boilerplate code is a typical source code that cannot be omitted by the language specification. Basically, the boilerplate code does not have a specific logic hence it becomes redundant code in implementation.

Following are the typical Boilerplate source code in Java language.
  • getter/setter methods for accessing the member variables
  • equals/hashCode methods
  • toString methods
  • Constructors
  • Closing process of resources (input and output stream, etc.)
  • Generation of the logger instance
In Lombok, the boilerplate code gets generated at the time of compilation thereby providing a mechanism to remove the redundant code from the source code developed by the developer.

Add Project Lombok Dependency to Maven Project

Follow below steps to setup Lombok in your Java projects:
  1. Create a simple maven project using - How to Create a Simple Maven Project in Eclipse article.
  2. Add the below dependency in your maven project pom.xml file:
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.4</version>
    <scope>provided</scope>
</dependency>
Since Lombok library is not required at the time of application execution, the appropriate scope is provided.

Adding the Lombok Plugin in IDE (Eclipse)

Here are the installation steps to setup eclipse for Windows:
  • Downloaded jar from https://projectlombok.org/download or use the jar which is downloaded from your maven build.
  • Execute command in terminal: java -jar lombok.jar
  • This command will open window as shown in the picture below, install and quit the installer and restart eclipse.
That's it !.

You can start using Lombok in maven project in Eclipse IDE. To learn more, check out the Complete Project Lombok Tutorial.

Project Lombok Articles

Comments