This document describes how to use maven-jflex-plugin, a Maven 2 plugin to call JFlex.
JFlex is a parser generator. Given a grammar, JFlex generate Java (TM) code to parse documents that follow this grammar. This document isn't intended to be a tutorial on the use of JFlex, you should consult the JFlex user manual
This plugin reads JFlex grammar definition files (.jflex ) and generates a corresponding Java parser (in target/generated-source/jflex by default).
This configuration generates java code of a parser for all grammar files (*.jflex , *.jlex , *.lex , *.flex ) found in src/main/jflex/ and its sub-directories. The name and package of the generated Java source code are the ones defined in the grammar. The generated Java source code is placed in target/generated-source/jflex , in sub-directories following the Java convention on package names.
pom.xml
<project>
<!-- ... -->
<build>
<plugins>
<plugin>
<groupId>de.jflex</groupId>
<artifactId>maven-jflex-plugin</artifactId>
<version>1.4.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!-- ... -->
</build>
<!-- ... -->
</project>
This generates the source for two grammars (src/main/lex/preprocessor.jflex and /pub/postrocessor.jflex ) as well as all grammar files found in src/main/jflex (and it sub-directories). The generated Java code is placed into src/main/java instead of /target/generated-sources/jflex .
in pom.xml
<plugin>
<groupId>de.jflex</groupId>
<artifactId>maven-jflex-plugin</artifactId>
<version>1.4.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<outputDirectory>src/main/java</outputDirectory>
<lexDefintions>
<lexDefinition>src/main/jflex</lexDefintion>
<lexDefinition>src/main/lex/preprocessor.jflex</lexFile>
<lexDefinition>/pub/postrocessor.jflex</lexFile>
</lexDefinitions>
</configuration>
</execution>
</executions>
</plugin>
More documentation on the configuration options can be found in the description for the generate goal .
This generates the source for
in pom.xml
<plugin>
<groupId>de.jflex</groupId>
<artifactId>maven-jflex-plugin</artifactId>
<version>1.4.3</version>
<executions>
<execution>
<id>strict jlex</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<lexDefintions>
<lexDefinition>src/main/lex</lexDefintion>
</lexDefinitions>
<jlex>true</jlex>
</configuration>
</execution>
<execution>
<id>jflex</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<lexDefintions>
<lexDefinition>src/main/jflex</lexDefintion>
</lexDefinitions>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
More information in the POM reference guide on plugins .