PMD and Static Code Analysis
PMD is a static code analysis tool, capable of automatically detecting a wide range of potential defects and unsafe or nonoptimized code. Whereas other tools, such as Checkstyle (see Chapter 21), can verify that coding conventions and standards are respected, PMD focuses more on preemptive defect detection. It comes with a rich and highly configurable set of rules, and you can easily configure which particular rules should be used for a given project. PMD integrates well with IDEs such as Eclipse and NetBeans, and it also fits well into the build process thanks to its smooth integration with Ant and Maven.
Using PMD in Eclipse
PMD is designed to integrate well into a developer’s work environment. Plug-ins exist for the principal IDEs, and they are the most productive and convenient way for a developer to use PMD. Plug-ins allow almost real-time code verification—they raise issues whenever you save the source code.
Installing the PMD Plug-In
The easiest way to install and use PMD under Eclipse is to use the remote update site, at http://pmd.sf.net/eclipse. You do this in the usual way:
Open the Help→Software Updates→Find and Install menu.
Click Next, and choose New Remote Site.
Now enter the URL of the remote site (http://pmd.sf.net/eclipse), and an appropriate name such as “PMD.”
Make sure that you have the PMD site checked in the “Sites to include in search” window, and click Finish. Then just go through the ...