PMD comes with several command line utilities. Previously, each of them had its own start up script, but this has been greatly simplified since PMD 5.0... at least for Unix systems. There is now only one script, called "run.sh", inside the bin/ directory of PMD distribution.
The first argument is the name of the utility you want to execute ('pmd', 'designer',...) and the other arguments are specific to the utility used.
$ ./bin/run.sh pmd -d ../../../src/main/java/ -f text -R rulesets/java/basic.xml -version 1.7 -language java .../src/main/java/net/sourceforge/pmd/RuleSet.java:123 These nested if statements could be combined .../src/main/java/net/sourceforge/pmd/RuleSet.java:231 Useless parentheses. .../src/main/java/net/sourceforge/pmd/RuleSet.java:232 Useless parentheses. .../src/main/java/net/sourceforge/pmd/RuleSet.java:357 These nested if statements could be combined .../src/main/java/net/sourceforge/pmd/RuleSetWriter.java:66 Avoid empty catch blocks .../src/main/java/net/sourceforge/pmd/RuleSetWriter.java:269 Useless parentheses.
C:\tmp\pmd-bin-5.0.5\pmd\bin>pmd -d c:\data\pmd\pmd\test-data\Unused1.java -f xml -R rulesets/java/unusedcode.xml <?xml version="1.0"?><pmd> <file name="c:\data\pmd\pmd\test-data\Unused1.java"> <violation line="5" rule="UnusedLocalVariable"> Avoid unused local variables such as 'fr' </violation> </file></pmd> C:\tmp\pmd-bin-5.0.5\pmd\bin>
You can pass a file name, a directory name, or a jar or zip file name containing Java source code to PMD.
Also, the PMD binary distribution includes the ruleset files inside the jar file - even though the "rulesets/java/unusedcode.xml" parameter above looks like a filesystem reference, it's really being used by a getResourceAsStream() call to load it out of the PMD jar file. And the same applies to the example below.
C:\tmp\pmd-bin-5.0.5\pmd>java -Djava.ext.dirs=lib net.sourceforge.pmd.PMD -d c:\j2sdk1.4.1_01\src\java\lang -f xml -R rulesets/java/imports.xml
/home/user/tmp/pmd-bin-5.0.5/pmd/bin>./run.sh pmd -d /home/user/data/pmd/pmd/test-data/Unused1.java -f xml -R rulesets/java/unusedcode.xml <?xml version="1.0"?><pmd> <file name="/home/user/data/pmd/pmd/test-data/Unused1.java"> <violation line="5" rule="UnusedLocalVariable"> Avoid unused local variables such as 'fr' </violation> </file></pmd> /home/user/tmp/pmd-bin-5.0.5/pmd/bin>