Lombok

Contents

Lombok

This page describes the potential support for Project Lombok in NetBeans. The support for Lombok is tracked under umbrella issue 173063.

New: Lombok now supports NetBeans! See this e-mail thread and this screencast by Alexis Moussine-Pouchkine.

Here are some scenarios how Lombok could be used in a practical project with NetBeans.

Simple scenario

  1. Create a Java application
  2. Create a new JavaBean (called MyBean) in this application, using the template available in NetBeans
  3. Add the following code to the main() method of the Main class:
    MyBean bean = new MyBean();
    bean.setSampleProperty("x");
    System.out.println(bean.getSampleProperty());
  4. Run the project - the application prints "x" to the console

    This is good, but when looking at the code of MyBean, we see that it contains boilerplate code (such as getters and setters). So how do we simplify the code using Lombok?
  5. Add Lombok library to the project
  6. Disable "Compile on Save" for this project (Compile on Save does not work with Lombok)
  7. Delete the getter and setter from the MyBean class
  8. Add the @Data annotation to MyBean. NetBeans will offer to import lombok.Data - do that.
  9. Run the application again - things work again, with less code!

Advanced scenario

  1. Create a Java Web application
  2. Create Java Persistence entity classes using the Entity Classes from Database wizard
  3. Create JSF pages for these entity classes using the JSF Pages from Entity Classes wizard
  4. Run the project

    We get a simple working application. But when looking at the generated entity classes, we see that these contain boilerplate code (such as getters and setters). So how do we simplify the code using Lombok?
  5. Add Lombok library to the project
  6. Disable "Deploy on Save" for this project (Deploy on Save does not work with Lombok)
  7. Delete the getters and setters from the entity classes
  8. Add the @Data annotation to the entity classes. NetBeans will offer to import lombok.Data - do that.
  9. Redeploy the application - things work again, with less code!

IDE support

The above can be done in NetBeans now, but there are many things that do not work correctly, or that could be improved. Let's track them under umbrella issue 173063.

Links

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo