Command Line

Description

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.

Installation

The easiest way is to include checkstyle-all-4.4.jar in the classpath. If you are running JDK 1.4 this contains all the classes required to run checkstyle (JDK 1.3 users must add a JAXP compliant XML parser implementation). Alternatively, you must include the following in the classpath:

  1. checkstyle-4.4.jar
  2. ANTLR 2.7.2 classes. antlr.jar is included in the distribution.
  3. Jakarta Commons Beanutils classes. commons-beanutils.jar is included in the distribution.
  4. Jakarta Commons Collections classes. commons-collections.jar is included in the distribution.
  5. Jakarta Commons Logging classes. commons-logging.jar is included in the distribution.
  6. Jakarta Commons CLI (command line interface) classes. commons-cli.jar is included in the distribution.
  7. JDK 1.3 only: A JAXP compliant XML parser implementation.

Usage

The command line usage is:

java -D<property>=<value>  \
     com.puppycrawl.tools.checkstyle.Main \
     -c <configurationFile> [-n <packageNameFile>] \
     [-f <format>] [-p <propertiesFile>] [-o <file>] \
     [-r <dir>] 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:

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.

Examples

Run checkstyle with configuration file docs/sun_checks.xml on a file

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 \
     -r 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

Run checkstyle with configuration file docs/sun_checks.xml on a file and provide a package names file

java com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \
     -n myPackageNames.xml Check.java

Tip

It is possible to run Checkstyle directly from the JAR file using the -jar option. An example would be:

java -jar checkstyle-all-4.4.jar \
     -c docs/sun_checks.xml Check.java
        
Copyright © 2001-2007, Oliver Burn