Subscribed unsubscribe Subscribe Subscribe

Kengo's blog

Technical articles about original projects, JVM, Static Analysis and JavaScript.

memo: How to generate code automatically for Java project

There are many way to generate code automatically. I think that the most common way is Annotation Processing Tool and Pluggable Annotation Processing API, but always I use PMD or ASM because I'm familiar with these libraries.

Annotation Processing Tool

The Annotation Processing Tool(APT) is JDK bundled tool. It's well known, but not standard and not supported commonly. For example, Maven plugin is still alpha version.

PMD

PMD is the most favorite source parser for me. It helps to parse Java and JSP. You don't have to use annotations.

PMD is a library, not a framework. We have to write a product to use automatically like Maven plugin. Maven plugin make it easy to give properties, search target file recursive, and unite with build system.

ASM

ASM is the most favorite bytecode library for me. It helps to parse & generate class file.

ASM is a library, not a framework. We have to write a product to use automatically like Maven plugin. I think that openjpa:enhance is one of the most famous example.