To enable the plugin, add the following to you project's pom.xml :
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
You should place your ANTLRv3 grammar files in src/main/antlr , and the plugin with scan the subfolders of this folder looking for grammar files (names ending with '.g').
The generated files will automatically be included in the list of elements to be built in the project's compile phase.
The generated code should just get compiled by running mvn compile etc. but you will need to include the ANTLR runtime classes as a dependency of your project. Add the following dependency to your POM:
...
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>3.0.1</version>
</dependency>
...
Ensure you add a dependency on the Java runtime rather than on the ANTLR tool artifact, or you will end up adding the transitive dependencies on StringTemplate and the old ANTLRv2 to your project, when all you need are the runtime support classes.
If you include java package directives in your grammar, e.g.
@parser::header {
package com.example;
}
You will need the generated Java files to be created within the appropriate folder structure (i.e. com/example ) otherwise the the Java compiler will report error messages.
To achieve the desired result, just put the source grammar file into a folder structure that matches the package structure, just as you would structure the folder containing a Java source file.
i.e. assuming the default source directory, the grammar with the header in the example above would need to be placed in the folder src/main/antlr/com/example .