Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added a note and link to the new plugin pages

Maven plugin for ANTLR 3

Info
titleNew plugin pages

These notes refer to an old version of the maven plugin. If you are using ANTLR 3.1.3 or above see the new plugin pages

If you are using Maven as your build management tool there is an ANTLRv3 plugin available. Add the following to the plugins section of your pom.xml

Code Block
xml
xml

            <plugin>
                <groupId>org.antlr</groupId>
                <artifactId>antlr3-maven-plugin</artifactId>
                <version>3.1.1.2</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>antlr</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

...

Panel
borderWidth0
No Format

 base.dir
         +--pom.xml
     +--src
        |
        +--main
           |
           +--java
           |  |
           |  +--org
           |     |
           |     +--eatmoreveg
           |        |
           |        +--VegApp.java
           |
           +--antlr
              |
              +--org
                 |
                 +--eatmoreveg
                    |
                    +--parser
                       |
                       +--Veg.g

In the grammar file...

Code Block

@header {
package org.eatmoreveg.parser;
}

@lexer::header {
package org.eatmoreveg.parser;
}

...

In VegApp.java...

Code Block

package org.eatmoreveg;

import org.eatmoreveg.parser.VegLexer;
import org.eatmoreveg.parser.VegParser;

...

If you want to share a tokens file between grammars you will need to set the libDirectory variable to tell the plugin where to find it, as in this example...

Code Block
xml
xml
            
    <plugin>
        <groupId>org.antlr</groupId>
        <artifactId>antlr3-maven-plugin</artifactId>
        <version>3.1.1.2</version>
        <configuration>
            <libDirectory>target/generated-sources/antlr/myorg/myproject/mypackage</libDirectory>
        </configuration>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                     <goal>antlr</goal>
                </goals>
            </execution>
        </executions>
    </plugin>