Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Project Lombok: Put an End to Java Verbosity

The introduction of Project Lombok, a combination compile-time and development-time code generator, has made Java POJO verbosity history. Add Lombok to your daily coding practices, and you won't go back.


advertisement
n my never-ending search for interesting new ideas in the IT world, every now and then I come across something truly innovative and brilliant. Such was the case when I first stumbled upon the initial announcement of Project Lombok. In the two months since then, Project Lombok has become an indispensable part of my Java tool chain and I can't imagine coding without it.

What Is Project Lombok?

Project Lombok is really two things: a compile-time code generator and a development-time code generator. It's the latter that makes it so brilliant.

Basically, Lombok integrates directly into the Eclipse compilation cycle (by manipulating the abstract syntax tree of your code as you type) and generates code immediately based on annotations. The generated code is visible to all other classes instantly.



What type of code can Lombok generate from annotations? Most importantly, it generates the basic boilerplate stuff that makes Java classes look so verbose, namely:

  • getters and setters for fields
  • toString() representation of your POJOs
  • hashCode() and equals()

At the same time, Lombok provides automatic resource management. For example, it always closes your streams safely, without the need for try/catch/finally statements.

Figure 1. The Lombok Installation Wizard: Upon running the lombok.jar file, a simple wizard will pop up.

Lombok Installation and Maven Support

Lombok is provided as an executable JAR file (lombok.jar), and the development-time support currently works only in Eclipse. Upon running the JAR file, a simple wizard will pop up and ask you to specify where your Eclipse executable is located (see Figure 1).

Just point to your Eclipse executable and press "Install/Update." You will need to do this for every new version of Lombok.

To include Maven support, just add the Project Lombok repository and dependencies to your pom.xml, as per the instructions on the project web site. After that, Lombok will work with Maven's compilation lifecycle out of the box.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap