Install and Use PMD plugin on NetBeans 6.5

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:

Plugins dialog

Plugins dialog

Click on ‘Add Plugins…’ and select downloaded pmd.nbm file:

PMD plugin selected for installation

PMD plugin selected for installation

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’:

PMD plugin is not signed

PMD plugin is not signed

Successfully installed plugin will be visible in the Plugins dialog in ‘Installed’ tab:

Successfully installed PMD plugin

Successfully installed PMD plugin

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:

pmd-6

Produced report contains location, name of the violated rule and recomandation how to solve the problem:

PMD report

PMD report

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.

pmd-8

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

PMD website

PMD on Wikipedia

PMD book

Tom Copeland’s blog (creator of PMD)

In next article I will show how to configure PMD rules.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s