How do I use ant with ANTLR 3?

For complete information, see How to use ant with ANTLR3.

  1. download ant-antlr3 task from
    http://www.antlr.org/share/1169924912745/antlr3-task.zip
  2. copy to where ant can see it. My mac:
    $ sudo cp /usr/local/lib/ant-antlr3.jar /usr/share/ant/lib/
    my linux box:
    $ sudo cp /tmp/ant-antlr3.jar /usr/local/apache-ant-1.8.1/lib/
    Then, this
    $ ant -diagnostics
    should show:
    -------------------------------------------
     ANT_HOME/lib jar listing
    -------------------------------------------
    ant.home: /usr/share/ant
    ant-antlr.jar (5758 bytes)
    ant-antlr3.jar (20628 bytes)   <---------
    ...
    
  3. make sure antlr2, antlr3, ST are in classpath. All in one is here:
    http://antlr.org/download/antlr-3.3-complete.jar
  4. use in build.xml
    	<path id="classpath">
    		<pathelement location="${antlr3.jar}"/>
    		<pathelement location="${ant-antlr3.jar}"/>
    	</path>
    
    	<target name="antlr" depends="init">
    		<antlr:ant-antlr3 xmlns:antlr="antlib:org/apache/tools/ant/antlr"
    			target="src/T.g"
    			outputdirectory="build">
    			<classpath refid="classpath"/>
    		</antlr:ant-antlr3>
    	</target>