Search code examples
javalombokjshell

How to use Lombok in jshell?


How I can use Lombok annotation in JShell?

I tried

* jshell --class-path lombok.jar
jshell> import lombok.*
jshell> @Data class Person { String name; String address; }
|  created class Person
jshell> new Person()
$3 ==> Person@6f7fd0e6
jshell> $3.setName("Hi")
|  Error:
|  cannot find symbol
|    symbol:   method setName(java.lang.String)
|  $3.setName("Hi")
|  ^--------^


Solution

  • It won't work. JShell doesn't support annotation processors as would be needed to make the Lombok annotations to work as you are expecting.

    See JDK-8213600 - JShell compilation does not take Lombok's annotation processor into account


    For a workaround, see https://stackoverflow.com/a/74084467/139985 or the bug report itself.

    Basically, you need to compile the Lombok code outside of jshell, and then import the compiled classes into your jshell session.