Unzip it into any directory, optionally add the bin subdirectory in your PATH, and you’re good to go!
Running PMD via command line
PMD comes with several command line utilities, like CPD, the rule designer or PMD itself.
On Unix, you can run any of them using the script run.sh, located inside the bin/
directory of the PMD distribution. The first argument is the name of the utility you want
to execute (‘pmd’, ‘designer’, …), e.g. PMD is launched via run.sh pmd. The rest of
the arguments are specific to the utility used.
On Windows, each utility has its own startup script, e.g. pmd.bat, cpd.bat.
The PMD command (pmd.bat or run.sh pmd) requires two options:
-d <path>: path to the sources to analyse. This can be a file name, a directory, or a jar or zip file containing the
-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.
Note: At the moment the formerly provided rulesets (eg rulesets/java/basic.xml) are deprecated,
though you can still use them. 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
The following shows a sample run of PMD with the text format: