Naanavanalla
Naanavanalla

Reputation: 1522

Generating getters and setters using project Lombok

I wanted to use Lombok dependency in my project. So, I downloaded lombok-1.16.18.jar and added to the build path of on of my classes. The configuration is shown below.

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@ToString(includeFieldNames=true)
public @Data class Student {

@Getter
@Setter
private Integer id;

@Getter
@Setter
private String name;

//private Date dob;
@Getter
@Setter
private String uid;

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Student s = new Student();
    System.out.println(s);


}
}

But, I am not getting proper output in console. I am getting Object classes toString() output like com.selflearn.sandesha.Student@7852e922 . I am also not able to use getters and setters. How to make Lombok work or what wrong I am doing?

Upvotes: 2

Views: 7252

Answers (5)

Sudarshan Nagre
Sudarshan Nagre

Reputation: 27

Simply download the lombok-1.18.24.jar(any version) and once download, double click on that file, so it checks your system and detects the IDE's that are available on your system. Then verify the IDE's and click on install/update button. Once the above process is completed, restart your IDE maybe, sts or eclipse.

Upvotes: 0

Naanavanalla
Naanavanalla

Reputation: 1522

thanks for your help. In eclipse IDE, I was not exporting the lombok jar. Even though, I added jar to the build path, it seems I should export it to the project in order and export section of eclipse.

So, In eclipse editor,

right click on your project --> Build Path--> Configure Build Path...-->select order and export tab and check the jar you want to export to your project.

Or

you can also simply run the downloaded jar. This will detect the possible IDE's in the system and configure it to support all lombok features.

This solved my issue. Again thank you for your support.

Upvotes: 0

Mesbah Gueffaf
Mesbah Gueffaf

Reputation: 548

If you use netbeans go to properties->Build->compiling for checked the option Enable Annotation processing

or search this option in your editor

Upvotes: 2

David Pérez Cabrera
David Pérez Cabrera

Reputation: 5048

Your configuration is incomplete. Review https://projectlombok.org/setup/eclipse and check if It compiles. When it does, try again!

Upvotes: 2

Jurrian Fahner
Jurrian Fahner

Reputation: 329

@Data on class level would be sufficient. Maybe it is a problem that you have put the @Data annotation between public and class.

Other question is whether your lombok.jar is on the classpath.

If I would rewrite your class, I would come up with the following:

@Data
public class Student {

private Integer id;

private String name;

private String uid;

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Student s = new Student();
    System.out.println(s);


}
}

Upvotes: -1

Related Questions