<!-- this highlights the active parent class in the navgoco sidebar. this is critical so that the parent expands when you're viewing a page. This must appear below the sidebar code above. Otherwise, if placed inside customscripts.js, the script runs before the sidebar code runs and the class never gets inserted.-->
<h1class="post-title-main">Installation and basic CLI usage</h1>
</div>
<divclass="post-content">
<divclass="summary">Sums up the first steps to set up a CLI installation and get started using PMD</div>
<!-- this handles the automatic toc. use ## for subheads to auto-generate the on-page minitoc. if you use html tags, you must supply an ID for the heading element in order for it to appear in the minitoc. -->
OpenJDK from <ahref="https://www.azul.com/downloads/zulu-community/">Azul</a>
or <ahref="https://adoptopenjdk.net/">AdoptOpenJDK</a> 1.7 or higher.</p>
<p><strong>Note:</strong> For analyzing Apex, JavaScript, Scala or VisualForce or running the <ahref="pmd_userdocs_extending_designer_reference.html">Designer</a>
<li>For Windows: <ahref="http://winzip.com">Winzip</a> or the free <ahref="http://www.7-zip.org/">7-zip</a></li>
<li>For Linux / Unix: <ahref="http://infozip.sourceforge.net/">InfoZip</a></li>
</ul>
</li>
</ul>
<divclass="alert alert-info"role="alert"><iclass="fa fa-info-circle"></i><b>Note:</b> For executing the Designer (./run.sh designer) using <ahref="http://jdk.java.net">OpenJDK</a> or Java 11, you need additionally <ahref="http://jdk.java.net">OpenJFX</a>. Download it, extract it and set the environment variable JAVAFX_HOME.</div>
<h3id="installation">Installation</h3>
<p>PMD is distributed as a zip archive, which includes both <ahref="#running-pmd-via-command-line">PMD</a> and <ahref="pmd_userdocs_cpd.html">CPD</a>.
You can download the latest binary distribution from <ahref="https://github.com/pmd/pmd/releases">the github releases page</a>.</p>
<p>Unzip it into any directory, optionally add the <codeclass="language-plaintext highlighter-rouge">bin</code> subdirectory in your <codeclass="language-plaintext highlighter-rouge">PATH</code>, and you’re good to go!</p>
<h2id="running-pmd-via-command-line">Running PMD via command line</h2>
<divclass="bs-callout bs-callout-primary">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 <codeclass="language-plaintext highlighter-rouge">run.sh</code>, located inside the <codeclass="language-plaintext highlighter-rouge">bin/</code>
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 <codeclass="language-plaintext highlighter-rouge">run.sh pmd</code>. The rest of
the arguments are specific to the utility used.<br/><br/>
On Windows, each utility has its own startup script, e.g. <codeclass="language-plaintext highlighter-rouge">pmd.bat</code>, <codeclass="language-plaintext highlighter-rouge">cpd.bat</code>.</div>
<p>The PMD command (<codeclass="language-plaintext highlighter-rouge">pmd.bat</code> or <codeclass="language-plaintext highlighter-rouge">run.sh pmd</code>) requires two options:</p>
<ul>
<li><codeclass="language-plaintext highlighter-rouge">-d <path></code>: path to the sources to analyse. This can be a file name, a directory, or a jar or zip file containing the
sources.</li>
<li><codeclass="language-plaintext highlighter-rouge">-R <path></code>: the ruleset file you want to use. PMD uses xml configuration files, called <em>rulesets</em>, which specify
which rules to execute on your sources. You can also run a single rule by referencing it using its <em>category</em> and
name (more details <ahref="pmd_userdocs_making_rulesets.html#referencing-a-single-rule">here</a>). For example, you can check for unnecessary
modifiers on Java sources with <codeclass="language-plaintext highlighter-rouge">-R category/java/codestyle.xml/UnnecessaryModifier</code>.</li>
</ul>
<divclass="alert alert-info"role="alert"><iclass="fa fa-info-circle"></i><b>Note:</b> At the moment the formerly provided rulesets (eg <codeclass="language-plaintext highlighter-rouge">rulesets/java/basic.xml</code>) 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. <codeclass="language-plaintext highlighter-rouge">rulesets/java/quickstart.xml</code>. You’re strongly
encouraged to <ahref="pmd_userdocs_making_rulesets.html">create your own ruleset</a> from the start though.</div>
<p>Additionally, the following options, are specified most of the time even though they’re not required:</p>
<ul>
<li><codeclass="language-plaintext highlighter-rouge">-f <format></code>: report format. PMD supports many report formats out of the box. You may want to start with the basic
<codeclass="language-plaintext highlighter-rouge">text</code> format (default) or <codeclass="language-plaintext highlighter-rouge">xml</code> format. The supported formats are <ahref="pmd_userdocs_cli_reference.html#available-report-formats">documented here</a>.</li>
<li><codeclass="language-plaintext highlighter-rouge">-auxclasspath <classpath></code>: 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 <ahref="pmd_rules_java_bestpractices.html#missingoverride">MissingOverride</a>,
require it to function properly.</li>
</ul>
<divclass="alert alert-success"role="alert"><iclass="fa fa-check-square-o"></i><b>Tip:</b> A full CLI reference, including report formats, is available under <ahref="pmd_userdocs_cli_reference.html">PMD CLI Reference</a></div>
<h3id="sample-usage">Sample usage</h3>
<p>The following shows a sample run of PMD with the <codeclass="language-plaintext highlighter-rouge">text</code> format:</p>
<h2id="running-cpd-via-command-line">Running CPD via command line</h2>
<divclass="alert alert-info"role="alert"><iclass="fa fa-info-circle"></i><b>Note:</b> CPD supports Java, JSP, C, C++, C#, Fortran and PHP source code, among other languages.
For the full list, see <ahref="pmd_userdocs_cpd.html#supported-languages">Supported Languages</a>.</div>
<p>Like for PMD, CPD is started on Unix by <codeclass="language-plaintext highlighter-rouge">run.sh cpd</code> and on Windows by <codeclass="language-plaintext highlighter-rouge">cpd.bat</code>.</p>
<p>There are two required parameters:</p>
<ul>
<li><codeclass="language-plaintext highlighter-rouge">--files <path></code>: path to the sources to analyse. This can be a file name, a
directory or a jar or zip file containing the sources.</li>
<li><codeclass="language-plaintext highlighter-rouge">--minimum-tokens <number></code>: the minimum token length which should be reported as a duplicate.</li>
</ul>
<divclass="alert alert-success"role="alert"><iclass="fa fa-check-square-o"></i><b>Tip:</b> CPD’s command-line reference, Ant task usage, and many examples are documented in the