This document describes how to run Checkstyle using the command line tool. The latest version of Checkstyle can be found at http://checkstyle.sourceforge.net. This command line tool is included in the Checkstyle distribution.
java -D<property>=<value> \ com.puppycrawl.tools.checkstyle.Main \ -c <configurationFile> \ [-f <format>] [-p <propertiesFile>] [-o <file>] \ [-t | --tree] [-T | --treeWithComments] [-J | treeWithJavadoc] [-j | --javadocTree] [-v] \ file...
Checkstyle will process the specified files and by default report errors to standard out in plain format. Checkstyle requires a configuration XML file that configures the checks to apply. Command line options are:
* Test method. * @return true
Note that the -n packageNamesFile option has been dropped for Checkstyle 5.0, because of significant changes regarding package name file handling. See for details.
Set the properties for expanded property values by either by assigning system properties using the -D<property>=<value> arguments to java or specifying a property file using the -p option. If a property file is specified, the system properties are ignored.
It is possible to run Checkstyle directly from the JAR file using the -jar option. Download latest checkstyle-6.18-all.jar. An example of run would be:
java -jar checkstyle-6.18-all.jar -c /sun_checks.xml MyClass.java java -jar checkstyle-6.18-all.jar -c /google_checks.xml MyClass.java
To run Checkstyle UI viewer for AST tree directly from the JAR file using the -jar option. Download latest checkstyle-6.18-all.jar. An example of run would be (path to java file is optional):
java -cp checkstyle-6.18-all.jar com.puppycrawl.tools.checkstyle.gui.Main MyClass.java
Download and compile:
git clone https://github.com/checkstyle/checkstyle.git cd checkstyle mvn clean compile
mvn exec:java -Dexec.mainClass="com.puppycrawl.tools.checkstyle.Main" \ -Dexec.args="-c /sun_checks.xml src/main/java "
mvn exec:java -Dexec.mainClass="com.puppycrawl.tools.checkstyle.gui.Main" \ -Dexec.args="src/main/java/com/puppycrawl/tools/checkstyle/Checker.java"
mvn clean package -Passembly java -jar target/checkstyle-X.X-SNAPSHOT-all.jar -c /sun_checks.xml MyClass.java
The easiest way is to include
checkstyle-6.18-all.jar in the
classpath. Alternatively, you must include the
compile third party dependencies listed in
Project Dependencies in the
classpath.
Run checkstyle with configuration file at
docs/sun_checks.xml on a filesystem
java com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \ Check.java
Run checkstyle with configuration file docs/sun_checks.xml on all Java files in a directory
java com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \ src/
Run checkstyle with configuration file docs/sun_checks.xml on a file and provide a system property
java -Dcheckstyle.cache.file=target/cachefile \ com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \ Check.java
Run checkstyle with configuration file docs/sun_checks.xml on a file and use properties in a file
java com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \ -p myCheckstyle.properties Check.java
Run checkstyle with configuration file docs/sun_checks.xml on a file and output to a file in XML format
java com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \ -f xml -o build/checkstyle_errors.xml Check.java