To run Spoon in command line, you first have to download the corresponding jar file on Maven Central (take the version with all dependencies).

When you have downloaded the desired version of Spoon, you can directly use it. To know how you use the jar file, launch it with --help argument. You see the output at the end of this page for the current release version of Spoon.

The basic usage of Spoon consists in defining the original source location and the list of compiled processors to be used.

$ java -classpath /path/to/binary/of/your/processor.jar:spoon-core--with-dependencies.jar spoon.Launcher -i /path/to/src/of/your/project -p fr.inria.gforge.spoon.processors.CatchProcessor

If you plan to repeatedly run Spoon from the command line, it may be a good idea to combine all of your commands into a single bash script. An example of this can be found here.

Note that when you use Spoon in command line, you manually handle the classpath. In particular, if the to-be-transformed source files depend on libraries, specify them with the --source-classpath flag.


Options : 

  [-h|--help]

  [--tabs]
        Use tabulations instead of spaces in the generated code (use spaces by
        default).

  [--tabsize <tabsize>]
        Define tabulation size. (default: 4)

  [--level <level>]
        Level of the output messages about what spoon is doing. (default: OFF)

  [--with-imports]
        Enable imports in generated files.

  [--compliance <compliance>]
        Java source code compliance level (1,2,3,4,5, 6, 7 or 8). (default: 8)

  [--encoding <encoding>]
        Forces the compiler to use a specific encoding (UTF-8, UTF-16, ...).
        (default: UTF-8)

  [(-i|--input) <input>]
        List of path to sources files.

  [(-p|--processors) <processors>]
        List of processor qualified name to be used.

  [(-t|--template) <template>]
        List of path to templates java files.

  [(-o|--output) <output>]
        Specify where to place generated java files. (default: spooned)

  [--source-classpath <source-classpath>]
        An optional classpath to be passed to the internal Java compiler when
        building or compiling the input sources.

  [--template-classpath <template-classpath>]
        An optional classpath to be passed to the internal Java compiler when
        building the template sources.

  [(-d|--destination) <destination>]
        An optional destination directory for the generated class files.
        (default: spooned-classes)

 --cpmode <cpmode>
        Classpath mode to use in Spoon: NOCLASSPATH; FULLCLASSPATH (default:
        NOCLASSPATH)

  [--output-type <output-type>]
        States how to print the processed source code:
        nooutput|classes|compilationunits (default: classes)

  [--compile]
        Enable compilation and output class files.

  [--lines]
        Set Spoon to try to preserve the original line numbers when generating
        the source code (may lead to human-unfriendly formatting).

  [-g|--gui]
        Show spoon model after processing

  [-r|--no-copy-resources]
        Disable the copy of resources from source to destination folder.

  [-j|--generate-javadoc]
        Enable the generation of the javadoc. Deprecated, use enable-comments
        argument.

  [-c|--enable-comments]
        Adds all code comments in the Spoon AST (Javadoc, line-based comments),
        rewrites them when pretty-printing.

  [(-f|--generate-files) <generate-files>]
        Only generate the given fully qualified java classes (separated by ':'
        if multiple are given).

  [-a|--disable-model-self-checks]
        Disables checks made on the AST (hashcode violation, method signature
        violation and parent violation). Default: false.