There are more than few tools that help us maintain the code we write correct and working. We can divide them in source code and class file analyzers.
One of them is PMD, tools that is actively developed since year 2000. It is mature and provides integration with all important IDEs. On the PMD website, developers say that PMD checks:
- Possible bugs – empty try/catch/finally/switch statements
- Dead code – unused local variables, parameters and private methods
- Suboptimal code – wasteful String/StringBuffer usage
- Overcomplicated expressions – unnecessary if statements, for loops that could be while loops
- Duplicate code – copied/pasted code means copied/pasted bugs
In this article we will show how it can be installed and used in NetBeans 6.5.
Installing the plugin
Download pmd-netbeans from sourceforge.
Decompress the archive to temporary location. Plugin file is called pmd.nbm
In NetBeans, open Tools -> Plugins and select ‘Downloaded’ tab:
Click on ‘Add Plugins…’ and select downloaded pmd.nbm file:
Click ‘Install’, confirm the plugin choice and accept the licence.
You will get a warning that plugin is not signed. Ignore it and click ‘Continue’:
Successfully installed plugin will be visible in the Plugins dialog in ‘Installed’ tab:
PMD Plugin is now ready for use.
Using PMD plugin
In order to obtain PMD report, right click on source packages directory in projects view and choose Tools -> Run PMD.
While analyzing the code, plugin will show progress bar in lower right corner:
Produced report contains location, name of the violated rule and recomandation how to solve the problem:
Double clicking on the issue will navigate to the class file and line where issue is detected. In the line numbers area we’ll see a PMD mark. Hovering the mouse above it will show a tooltip with the error description.
In next article we will show how to customize PMD rules. Please come back soon.
Related Posts
Customizing PMD rules on NetBeans 6.5
You can check tutorial for installing Code Coverage plugin here.
Useful links
Tom Copeland’s blog (creator of PMD)
In next article I will show how to configure PMD rules.






0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.