GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • PMD Source Code Analyzer Project
  • Nav
  • Download
  • GitHub
  • Edit on GitHub

This view

  • Original page
  • New address

GeezerVison is showing docs.pmd-code.org — Installation and basic CLI usage | PMD Source Code Analyzer

 
  • PMD 7.30.0
  • Release date: 27-November-2026
  • About
    • Home
    • Release notes
    • Getting help
    • Release policies
    • Support lifecycle
    • Security
  • User Documentation
    • Migration Guide for PMD 7
    • Installation and basic CLI usage
    • Making rulesets
    • Configuring rules
    • Best practices
    • Suppressing warnings
    • Incremental analysis
    • PMD CLI reference
    • PMD Report formats
    • 3rd party rulesets
    • Signed Releases
    • CPD reference
      • Copy-paste detection
      • CPD Report formats
    • Extending PMD
      • Introduction to writing rules
      • Your first rule
      • XPath rules
      • Java rules
      • Rule designer reference
      • Defining rule properties
      • Rule guidelines
      • Testing your rules
      • Creating (XML) dump of the AST
    • Tools / Integrations
      • Maven PMD Plugin
      • Gradle
      • Ant
      • PMD Java API
      • bld PMD Extension
      • CI integrations
      • IDE Plugins
      • Other Tools / Integrations
  • Rule Reference
    • Apex Rules
      • Index
      • Best Practices
      • Code Style
      • Design
      • Documentation
      • Error Prone
      • Performance
      • Security
    • HTML Rules
      • Index
      • Best Practices
    • Java Rules
      • Index
      • Best Practices
      • Code Style
      • Design
      • Documentation
      • Error Prone
      • Multithreading
      • Performance
      • Security
    • Java Server Pages Rules
      • Index
      • Best Practices
      • Code Style
      • Design
      • Error Prone
      • Security
    • JavaScript Rules
      • Index
      • Best Practices
      • Code Style
      • Error Prone
      • Performance
    • Kotlin Rules
      • Index
      • Best Practices
      • Error Prone
    • Maven POM Rules
      • Index
      • Error Prone
    • Modelica Rules
      • Index
      • Best Practices
    • PLSQL Rules
      • Index
      • Best Practices
      • Code Style
      • Design
      • Error Prone
    • Salesforce Visualforce Rules
      • Index
      • Security
    • Scala Rules
      • Index
    • Swift Rules
      • Index
      • Best Practices
      • Error Prone
    • Velocity Template Language (VTL) Rules
      • Index
      • Best Practices
      • Design
      • Error Prone
    • WSDL Rules
      • Index
    • XML Rules
      • Index
      • Best Practices
      • Error Prone
    • XSL Rules
      • Index
      • Code Style
      • Performance
  • Language-Specific Documentation
    • Overview
    • Language configuration
    • Apex
    • C/C++
    • C#
    • CSS
    • Coco
    • Dart
    • Fortran
    • Gherkin
    • Go
    • HTML
    • Java
    • JavaScript / TypeScript
    • JSP
    • Julia
    • Kotlin
    • Lua
    • Matlab
    • Modelica
    • Objective-C
    • Perl
    • PHP
    • PLSQL
    • Python
    • Ruby
    • Rust
    • Scala
    • Swift
    • T-SQL
    • Visualforce
    • Velocity Template Language (VTL)
    • XML and XML dialects
  • Developer Documentation
    • Contributing
      • Contributing
      • Developer resources
      • Newcomers' Guide
      • Writing documentation
    • Building PMD
      • General Info
      • Building PMD from source
      • Building PMD with IntelliJ IDEA
      • Building PMD with Eclipse IDE
      • Building PMD with VS Code IDE
      • Building PMD with Netbeans IDE
    • Roadmap
    • GitHub Actions Workflows
    • How PMD works
    • Logging
    • Pmdtester
    • Rule Deprecation Policy
    • Major contributions
      • Rule Guidelines
      • Adding a new dialect
      • Adding a new language (JavaCC)
      • Adding a new language (ANTLR)
      • Adding a new CPD language
    • Experimental features
      • List of experimental Features
  • Project documentation
    • Trivia about PMD
      • PMD in the press
      • Products & books related to PMD
      • Similar projects
      • What does 'PMD' mean?
    • Logo
    • FAQ
    • License
    • Credits
    • Old Release Notes
      • Release Notes PMD 7.x
      • Detailed Release Notes PMD 7.0.0
      • Release Notes PMD 6.x
      • Release Notes PMD 5.x
      • Release Notes PMD 4.x and earlier
    • Decisions
    • Project management
      • Infrastructure
      • Release process
      • Merging pull requests
      • Main Landing page

Installation and basic CLI usage

Sums up the first steps to set up a CLI installation and get started using PMD
Table of Contents

How to install PMD and CPD

Requirements

  • Java 8 or above: Java JRE, OpenJDK from Azul or Adoptium.

  • A zip archiver, e.g.:

    • For Windows: Winzip or the free 7-zip
    • For Linux / Unix: InfoZip

Note

For executing the Designer (pmd designer) using OpenJDK or Java 11+, you need additionally JavaFX. Download it, extract it and set the environment variable JAVAFX_HOME pointing at that directory. Java 9 and 10 are not supported. See The rule designer.

Installation

PMD is distributed as a zip archive, which includes both PMD and CPD. You can download the latest binary distribution from the github releases page.

It’s highly recommended (but not required) to include it to your PATH.

On Linux you can do this by adding PATH=$PATH:*path_to_pmd*/bin/ to your ~/.bashrc / ~/.zshrc file.

On Windows this is achieved by:

  1. On the Start menu, right-click Computer.
  2. On the context menu, click Properties.
  3. In the System dialog box, click Advanced system settings.
  4. On the Advanced tab of the System Properties dialog box, click Environment Variables
  5. In the System Variables box of the Environment Variables dialog box, scroll to Path and select it.
  6. Click the lower of the two Edit buttons in the dialog box.
  7. In the Edit System Variable dialog box, scroll to the end of the string in the Variable value box and add a semicolon (;).
  8. Add the proper value for *path_to_pmd*/bin/ after the semicolon.
  9. Click OK in three successive dialog boxes, and then close the System dialog box.

Shell completion

PMD ships with built-in completion support for Bash / Zsh.

To enable it, simply add source <(pmd generate-completion) to your ~/.bashrc / ~/.zshrc file.

Running PMD via command line

PMD comes with several command line utilities, like CPD, the rule designer or PMD itself. You can run any of them using the script pmd (pmd.bat under Windows), located inside the bin/ directory of the PMD distribution. The first argument is the name of the utility you want to execute (‘check’, ‘designer’, …), e.g. PMD is launched via pmd check. The rest of the arguments are specific to the utility used.

Running a PMD analysis (pmd check or pmd.bat check) requires at least one option and a list of sources:

  • -R <path>: the ruleset file you want to use. PMD uses xml configuration files, called rulesets, which specify which rules to execute on your sources. You can also run a single rule by referencing it using its category and name (more details here). For example, you can check for unnecessary modifiers on Java sources with -R category/java/codestyle.xml/UnnecessaryModifier.
  • <source> …: path to the sources to analyse. This can be a file name, a directory, or a jar or zip file containing the sources. Alternatively You can use the -d or --dir flag, which is equivalent.

Note

PMD includes a quickstart ruleset for some languages (currently, Java) as base configurations, which you can reference as e.g. rulesets/java/quickstart.xml. You’re strongly encouraged to create your own ruleset from the start though.

Additionally, the following options, are specified most of the time even though they’re not required:

  • -f <format>: report format. PMD supports many report formats out of the box. You may want to start with the basic text format (default) or xml format. The supported formats are documented here.
  • --aux-classpath <classpath>: class path containing the compiled class files of the analysed Java sources, if any. Setting this up correctly allows PMD to do much deeper analysis using reflection. Some rules, such as MissingOverride, require it to function properly.

Tip

A full CLI reference, including report formats, is available under PMD CLI Reference.

Sample usage

The following shows a sample run of PMD with the text format:

  • Linux / macOS
  • Windows
~ $ pmd check -f text -R rulesets/java/quickstart.xml src/main/java

.../src/main/java/com/me/RuleSet.java:123  These nested if statements could be combined
.../src/main/java/com/me/RuleSet.java:231  Useless parentheses.
.../src/main/java/com/me/RuleSet.java:232  Useless parentheses.
.../src/main/java/com/me/RuleSet.java:357  These nested if statements could be combined
.../src/main/java/com/me/RuleSetWriter.java:66     Avoid empty catch blocks
C:\> pmd.bat check -f text -R rulesets/java/quickstart.xml ..\..\src\main\java

...\src\main\java\com\me\RuleSet.java:123  These nested if statements could be combined
...\src\main\java\com\me\RuleSet.java:231  Useless parentheses.
...\src\main\java\com\me\RuleSet.java:232  Useless parentheses.
...\src\main\java\com\me\RuleSet.java:357  These nested if statements could be combined
...\src\main\java\com\me\RuleSetWriter.java:66     Avoid empty catch blocks

Running CPD via command line

Note

CPD supports Java, JSP, C, C++, C#, Fortran and PHP source code, among other languages. For the full list, see Supported Languages.

Like for PMD, CPD is started on Unix by pmd cpd and on Windows by pmd.bat cpd, and it requires one option and a list of sources:

  • --minimum-tokens <number>: the minimum token length which should be reported as a duplicate.
  • <source> …: path to the sources to analyse. This can be a file name, a directory, or a jar or zip file containing the sources. Alternatively You can use the -d or --dir flag, which is equivalent.

Tip

CPD’s command-line reference, Ant task usage, and many examples are documented in the CPD documentation page

Sample usage

The following shows a sample run of CPD with the text format:

  • Linux / macOS
  • Windows
~ $ pmd cpd --minimum-tokens 100 /home/me/src

Found a 7 line (110 tokens) duplication in the following files:
Starting at line 579 of /home/me/src/test/java/foo/FooTypeTest.java
Starting at line 586 of /home/me/src/test/java/foo/FooTypeTest.java

assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
C:\> pmd.bat cpd --minimum-tokens 100 c:\temp\src

Found a 7 line (110 tokens) duplication in the following files:
Starting at line 579 of c:\temp\src\test\java\foo\FooTypeTest.java
Starting at line 586 of c:\temp\src\test\java\foo\FooTypeTest.java

assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
Tags: getting_started userdocs
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.