Checkstyle Command Line - Version 2.4

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-2.4.jar in the classpath. This contains all the classes required to run checkstyle. Alternatively, you must include the following in the classpath:

  1. checkstyle-2.4.jar
  2. ANTLR 2.7.1 classes. antlr.jar is included in the distribution.
  3. Jakarta Regexp 1.2 classes. jakarta-regexp-1.2.jar is included in the distribution.

Usage

The command line usage is:

  java -D<property>=<value>  \
       com.puppycrawl.tools.checkstyle.Main \
       [-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. The options are:

The default behaviour of checkstyle can be changed either by setting system properties using the -D<property>=<value> arguments to java or by specifying a property file using the -p option. See here for all available configuration options. If a property file is specified the system properties are ignored. The following table describes what properties can be set:

Examples

Run checkstyle on a file

  java  com.puppycrawl.tools.checkstyle.Main  Check.java

Run checkstyle on all java files in a directory

  java  com.puppycrawl.tools.checkstyle.Main -r src/

Run checkstyle on a file and use specified properties

  java  com.puppycrawl.tools.checkstyle.Main \
        -p myCheckstyle.properties Check.java

Run checkstyle on a file and output to a file in XML format with Australian localisation

  java  -Dcheckstyle.allow.tabs=yes  \
        -Dcheckstyle.locale.language=en \
        -Dcheckstyle.locale.language=au \
        com.puppycrawl.tools.checkstyle.Main \
        -f xml -o build/checkstyle_errors.xml Check.java

Run checkstyle on a file and disable pattern matching

  java  -Dcheckstyle.pattern.parameter=. \
        -Dcheckstyle.pattern.static=. \
        -Dcheckstyle.pattern.const=. \
        -Dcheckstyle.pattern.member=. \
        com.puppycrawl.tools.checkstyle.Main Check.java

Tip

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

  java  -jar checkstyle-all-2.4.jar  Check.java

Copyright © 2001 Oliver Burn. All rights Reserved.