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
- Maven PMD plugin
- NetBeans PMD plugin
- JBuilder PMD plugin
- JDeveloper PMD plugin
- IntelliJ PMD plugin
Required Libraries
You need to download
You can install the PMD Eclipse plugin using Eclipse update manager from the following links
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
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
Using PMD Eclipse Plugin
Finding bugs using PMD, you need to create a java project and add the following class into src
//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.
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)
You can see below how to generate reports using PMD (please check the screenshot below)
Now you can see the generated reports inside the project folder (in our case we can see a separate reports folder inside PMDTest project)