PMD Eclipse Tutorial

PMD Eclipse Tutorial explains step by step details of installing and configuring PMD plugin with eclipse.

How to configure PMD plugin with eclipse?

How to generate PMD reports with eclipse?

What is PMD? How to use PMD?

PMD  stands for Programming Mistake Detector. It is a free source code analysis tool which helps you to find the bugs in your java code and improve the code quality. PMD helps to find empty try/catch/finally statements, while/if statements, unnecessary object creation etc.

PMD warning and problems are not exactly errors, but shows that particular code need to be improved

Following plugins are available for PMD

  1. Maven PMD plugin
  2. NetBeans PMD plugin
  3. JBuilder PMD plugin
  4. JDeveloper PMD plugin
  5. IntelliJ PMD plugin
Note

Findbugs is another source code analysis tool, you can configure FindBugs plugin same as PMD, please refer this article for using FindBugs FindBugs In Eclipse Tutorial

If you interested on Eclipse Checkstyle Tutorial (another code analysis tool), You can follow Eclipse Checkstyle Tutorial

If you interested on Sonar Eclipse Plugin (another source code analysis tool), You can follow Eclipse Sonar Tutorial

Required Libraries

You need to download

  1. Eclipse 4.2
  2. PMD

You can install the PMD Eclipse plugin using Eclipse update manager from the following links

  1. http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/

PMD Eclipse Installation

For Installing PMD Plugin from eclipse, select Help->Install New Software Then click add, then provide Name and Location according to the following screenshot

PMD Installation

Then select the PMD version click next and accept the license details, it will install the PMD

PMD Eclipse Configuration

After install, you can configure PMD from eclipse, Window->Preferences->Java->PMD

Here you can apply PMD Rules, in order to utilizing different rules on PMD bug patterns, you can also configure different reports here

PMD Configuration

Using PMD Eclipse Plugin

Finding bugs using PMD, you need to create a java project and add the following class into src

package test.pmd;

//PMD Eclipse Tutorial
public class PMDTest {
 
public static void main(String args[]) {
   
PMDTest.CALL_METHOD("hello");
    PMDTest.CallHello
();
 
}

 
public static void CALL_METHOD(String INPUT_PARAMETER) {
   
System.out.println(INPUT_PARAMETER);
 
}

 
public static void CallHello() {
   
System.out.println("Hello PMD World!");
 
}
}

Running PMD

Then, Build the project using Project->Build Project. Right click on the project, and run the PMD according to following screenshot.

Running PMD

Now you can see a bug mark on the source code, double click the bug mark, Bug Explorer will be shown ( You can also navigate to Window->Show View->Other->PMD->Violations Overview).

How To Generate Reports Using PMD?

You can generate reports in various formats by using PMD, you can configure this in PMD settings (please check the screenshot below)

Select PMD Reports

You can see below how to generate reports using PMD (please check the screenshot below)

Generate PMD Reports

Now you can see the generated reports inside the project folder (in our case we can see a separate reports folder inside PMDTest project)









Your email address will not be published. Required fields are marked *