This is currently not possible as described by this bug report.
The workaround that is mentioned there is to compile your class externally. For that, you basically have to follow the following steps:
- Create some directory, e.g.
com/example
.
- Put the
Person
class below in that directory.
package com.example;
import lombok.*;
@Data
public class Person {
private String name;
private int age;
}
- Compile the class with:
javac -cp lombok.jar com/example/Person.java
- Create an archive with:
jar -cf person.jar com/
- Run JShell:
jshell --class-path "person.jar:lombok.jar"
- Create a
Person
:
> import com.example.*;
> var p = new Person();
Also note that JShell cannot access classes that are in the default package (as described here) which is why we put Person
in com.example
.