Fork me on GitHub

JavaCC Maven Plugin

This plugin uses the JavaCC parser generator to process JavaCC grammar files and generate the appropriate Java source files. For general information about JavaCC, see the JavaCC web site.

JavaCC grammar files use the extension .jj. This plugin can be used to locate and process all grammar files within a specified directory. Java source files will be written to a common generated-sources output directory, typically located in the build output directory. By default, the plugin will run during the generate-sources phase, but it can be configured to run in other phases as well.

The plugin can also be be used to call the JJTree and JTB tools. JJTree is a preprocessor for JavaCC that inserts parse tree building actions at various places in the JavaCC source. More information about JJTree can be found on the JJTree site.

JTB (Java Tree Builder) is another syntax tree builder. Just like JJTree, it works as a preprocessor for JavaCC grammar files and inserts code to build syntax trees from a parsed input stream. More information about JTB in general and a feature comparison with JJTree can be found on the JTB web site.

Finally, this plugin contains a goal for running JJDoc. JJDoc is a simple tool that generates BNF documentation for the JavaCC grammar files. This can be used to generate a report for your project site using the Maven reporting tools.

Goals Overview

The following goals are meant to participate in the default build lifecycle:

  • javacc:javacc
    Runs JavaCC on grammar files (*.jj) to generate a Java parser.
  • javacc:jjtree-javacc
    Runs JJTree and JavaCC in a pipeline to process annotated grammar files (*.jjt).
  • javacc:jjtree
    Deprecated. Preprocesses annotated grammar files (*.jjt) with JJTree.
  • javacc:jtb-javacc
    Runs JTB and JavaCC in a pipeline to process ordinary grammar files (*.jtb).
  • javacc:jtb
    Deprecated. Preprocesses ordinary grammar files (*.jtb) with JTB.

This last goal is intended for usage with the site lifecycle:

  • javacc:jjdoc
    Generates BNF documentation from the grammar files for usage as a site report.


General instructions on how to use the JavaCC Plugin can be found on the usage page. Some more specific use cases are described in the examples given below. Last but not least, users occasionally contribute additional examples, tips or errata to the plugin's wiki page.

In case you still have questions regarding the plugin's usage, please have a look at the FAQ and feel free to contact the user mailing list. The posts to the mailing list are archived and could already contain the answer to your question as part of an older thread. Hence, it is also worth browsing/searching the mail archive.

If you feel like the plugin is missing a feature or has a defect, you can fill a feature request or bug report in our issue tracker. When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. Of course, patches are welcome, too. Contributors can check out the project from our source repository and will find supplementary information in the development guidelines.


To provide you with better understanding of some usages of the JavaCC Plugin, you can take a look into the following examples: