37

I have the lombok plugin in Eclipse and enabled annotation processing in Eclipse under java compiler, but still it is unable to recognize the log statements when I use @Slf4j annotation.

Do we have to make any other settings?

Roel Spilker
  • 32,258
  • 10
  • 68
  • 58
bashwin
  • 373
  • 1
  • 3
  • 5
  • 1
    Lombok generates actual methods in the bytecode. Take a look at the Slf4j annotation. Is it looking for a method/field? Lombok should compile before this hits. Make sure eclipse is set up properly for Lombok. – Daniel B. Chapman May 18 '13 at 19:22
  • can you tell me what do you mean by Make sure "eclipse is set up properly for Lombok." – bashwin May 19 '13 at 19:52
  • 1
    Did you install Lombok via the installer? Make sure an "@Data" POJO shows methods for getter/setter/toString. Lombok causes the bytecode to compile the methods. That's its "Magic". That's why I'm guessing it isn't installed (merely a guess) – Daniel B. Chapman May 19 '13 at 20:41
  • You are absolutely true!! thanks for your help. I never realized that we need to install lobmbak separately. Downloaded lombak jar and manually installed .. that did the trick.. – bashwin May 20 '13 at 19:04
  • Possible duplicate of [Cannot make Project Lombok work on Eclipse (Helios)](https://stackoverflow.com/questions/3418865/cannot-make-project-lombok-work-on-eclipse-helios) – Kukeltje Nov 01 '19 at 16:45

4 Answers4

48

You also have to install Lombok into Eclipse.

See also this answer on how to do that or check if Lombok is installed correctly.

Full Disclosure: I am one of the Project Lombok developers.

Community
  • 1
  • 1
Roel Spilker
  • 32,258
  • 10
  • 68
  • 58
  • 1
    Why can't it be like the m2 eclipse plugin ? – Stephane Feb 03 '16 at 08:17
  • I add to remove the entries of my STS.ini files and restart Eclipse. Lombok was making it build for ever. – Stephane Feb 03 '16 at 08:56
  • 1
    I have no idea what you mean by "like the m2 eclipse plugin", but lombok cannot be a regular plugin because we modify existing eclipse code instead of adding new features. We need to change the bytecode of the eclipse java parser and compiler to allow code completion etc. Otherwise we would have to replace the entire java development tools. – Roel Spilker Feb 03 '16 at 15:36
  • @RoelSpilker I have written my wrapper around log I want to use my wrapper implementation. How can i do this using annotation ??? – vaibhav Feb 25 '17 at 16:28
  • I don't think you can do it using this annotation. If you are using Slf4j, you can register your implementation there. – Roel Spilker Feb 27 '17 at 08:43
  • 2
    If mine is a maven project , why do i need to still have a eclipse plugin even after adding the lambok jar as dependency in pom? I don't get the reason... – Stunner Oct 07 '20 at 10:02
15

I also faced the similar issue on log and @Slf4j on my STS environment. To resolve this, here is what I did on spring tool suite (sts-4.4.0.RELEASE) and lombok-1.18.10.jar (current latest version available in mavenrepository).

  1. If having maven project, ensure lombok dependency added to it. Else you need manually add the jar to your project classpath.

    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> <scope>provided</scope> </dependency>

  2. Clean build the maven application. This will download lombok jar in your .m2 location by default from maven repository. The path would be org\projectlombok\lombok\1.18.10\

  3. Now open command prompt and navigate to the lombok path and execute command java -jar lombok-1.18.10.jar

    C:\xxx\xxx\org\projectlombok\lombok\1.18.10>java -jar lombok-1.18.10.jar

  4. Opens up lombok dialog box. If see message Can't find IDE Click Specify location... Provide the path to your STS root location

    My case it is C:\apps\sts-4.4.0.RELEASE\SpringToolSuite.exe

    Install/Update

  5. Install successful Click Quit Installer

  6. Now in explorer navigate to your STS root path. C:\apps\sts-4.4.0.RELEASE\ We see lombok.jar placed in the sts root path Now edit in notepad SpringToolSuite4.ini file We see following appended at the end

    -javaagent:C:\apps\sts-4.4.0.RELEASE\lombok.jar

  7. Start STS using SpringToolSuite4.exe Clean, rebuild your project.

vinsinraw
  • 2,003
  • 1
  • 16
  • 18
  • 1
    This worked like a charm! Thanks so much! At first I didn't cycle STS but once I exited and restarted I was able to clean, build and launch the application. – sp_conway Sep 17 '20 at 21:58
  • 1
    I followed all these steps and it worked for me as well!! Thanks for the steps. @vinsinraw – Abhinandan Jan 28 '22 at 05:01
  • I'm working on a Mac, and my system wouldn't let me 'search' to the executable. So I followed the steps here: https://stackoverflow.com/questions/3418865/cannot-make-project-lombok-work-on-eclipse/3425327#3425327 to add the necessary info to the .ini file to get it to work. – amracel Nov 18 '22 at 12:55
10

So like others, i also faced this issue. Below is what I did.

  1. Installed lombok.jar like explained here.
  2. Tried restarting eclipse. (Did not work)
  3. Tried refreshing gradle project. (Did not work)
  4. tried what Hervian suggested in his answer here. (Did not work)
  5. Closed the projects, deleted from workspace and then re-imported. Bam!! Worked.
Manish Bansal
  • 2,400
  • 2
  • 21
  • 37
1

this got the fix to me by adding the slf4j dependency, Lombok can identify the slf4j but does not get the download, this is true for java project if you are using spring boot then slf4j comes by default.

here are my dependencies

    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>




    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.6</version>
        <scope>provided</scope>
    </dependency>
Naveen
  • 491
  • 5
  • 6