<p>I'm trying to call an Antlr task in my Ant build.xml as follows:</p>

<pre><code>&lt;path id="classpath.build"&gt;
  &lt;fileset dir="${dir.lib.build}" includes="**/*.jar" /&gt;
&lt;/path&gt;

...

&lt;target name="generate-lexer" depends="init"&gt;
  &lt;antlr target="${file.antlr.lexer}"&gt;
    &lt;classpath refid="classpath.build"/&gt;
  &lt;/antlr&gt;
&lt;/target&gt;
</code></pre>

<p>But Ant can't find the task definition.  I've put all of the following in that <code>dir.lib.build</code>:</p>

<ul>
<li>antlr-3.1.jar</li>
<li>antlr-2.7.7.jar</li>
<li>antlr-runtime-3.1.jar</li>
<li>stringtemplate-3.2.jar</li>
</ul>

<p>But none of those seems to have the task definition.  (I've also tried putting those jars in my Ant classpath; same problem.)</p>

[{'answer_id': 25484, 'author': 'James A. Rosen', 'author_id': 1190, 'author_profile': 'https://Stackoverflow.com/users/1190', 'pm_score': 3, 'selected': True, 'text': '<p>The current Antlr-task jar is available at <a href="http://www.antlr.org/share/1169924912745/antlr3-task.zip" rel="nofollow noreferrer">http://www.antlr.org/share/1169924912745/antlr3-task.zip</a></p>\n\n<p>It can be found on the <a href="http://antlr.org" rel="nofollow noreferrer">antlr.org</a> website under the "File Sharing" heading.</p>\n'}, {'answer_id': 25487, 'author': 'stimms', 'author_id': 361, 'author_profile': 'https://Stackoverflow.com/users/361', 'pm_score': 2, 'selected': False, 'text': '<p>You should use the antlrall.jar jar.  You can go ahead and just drop it into your Ant installation but that does mean that it will only work for that one install.  We check the jar in and use taskdef to load the jar file so that it doesn\'t become another step for developers when they start on the team or move to a new computer.  </p>\n\n<ul>\n<li>Antlr <a href="http://ant.apache.org/manual/Tasks/antlr.html" rel="nofollow noreferrer">http://ant.apache.org/manual/Tasks/antlr.html</a></li>\n<li>Using taskdef <a href="http://www.onjava.com/pub/a/onjava/2004/06/02/anttask.html" rel="nofollow noreferrer">http://www.onjava.com/pub/a/onjava/2004/06/02/anttask.html</a></li>\n</ul>\n'}, {'answer_id': 4515467, 'author': 'Terence Parr', 'author_id': 275496, 'author_profile': 'https://Stackoverflow.com/users/275496', 'pm_score': 2, 'selected': False, 'text': '<p>I just got this working for myself. Took me an hour. ugh. anyway,</p>\n\n<p>Step 1: download ant-antlr3 task from</p>\n\n<p><a href="http://www.antlr.org/share/1169924912745/antlr3-task.zip" rel="nofollow">http://www.antlr.org/share/1169924912745/antlr3-task.zip</a></p>\n\n<p>Step 2: copy to where ant can see it. My mac:</p>\n\n<p>sudo cp /usr/local/lib/ant-antlr3.jar /usr/share/ant/lib/</p>\n\n<p>my linux box:</p>\n\n<p>sudo cp /tmp/ant-antlr3.jar /usr/local/apache-ant-1.8.1/lib/</p>\n\n<p>Step 3: make sure antlr2, antlr3, ST are in classpath. All in one is here:</p>\n\n<p><a href="http://antlr.org/download/antlr-3.3-complete.jar" rel="nofollow">http://antlr.org/download/antlr-3.3-complete.jar</a></p>\n\n<p>Step 4: use in build.xml</p>\n\n<pre><code>&lt;path id="classpath"&gt;\n    &lt;pathelement location="${antlr3.jar}"/&gt;\n    &lt;pathelement location="${ant-antlr3.jar}"/&gt;\n&lt;/path&gt;\n\n&lt;target name="antlr" depends="init"&gt;\n    &lt;antlr:ant-antlr3 xmlns:antlr="antlib:org/apache/tools/ant/antlr"\n        target="src/T.g"\n        outputdirectory="build"&gt;\n        &lt;classpath refid="classpath"/&gt;\n    &lt;/antlr:ant-antlr3&gt;\n&lt;/target&gt;\n</code></pre>\n\n<p>Just added a faq entry:</p>\n\n<p><a href="http://www.antlr.org/wiki/pages/viewpage.action?pageId=24805671" rel="nofollow">http://www.antlr.org/wiki/pages/viewpage.action?pageId=24805671</a></p>\n'}, {'answer_id': 6350676, 'author': 'Andy Balaam', 'author_id': 22610, 'author_profile': 'https://Stackoverflow.com/users/22610', 'pm_score': 0, 'selected': False, 'text': '<p>On Ubuntu this should make it available:</p>\n\n<p><code>sudo apt-get install ant-optional</code></p>\n'}, {'answer_id': 10456313, 'author': 'Bruno Girin', 'author_id': 1175223, 'author_profile': 'https://Stackoverflow.com/users/1175223', 'pm_score': 0, 'selected': False, 'text': '<p>Additional info on top of what everybody else contributed so far:</p>\n\n<p>The <code>ant-optional</code> package in Ubuntu includes the task shipped with Ant 1.8.2 which is a task for ANTLR 2.7.2 so this will fail with an error as described <a href="https://stackoverflow.com/questions/6866580/why-does-my-antlr-build-ant-task-fail-with-unable-to-determine-generated-class">in this post</a>. The method described by Terence is the best way to use the ANTLR3 task.</p>\n\n<p>If you do not have root access on a Linux machine, you can install the ant-antlr3.jar file in the Ant user directory: <code>~/.ant/lib</code>. Check with <code>ant -diagnostics</code> whether ant-antlr3.jar is visible to Ant, as explained <a href="http://www.antlr.org/wiki/display/ANTLR3/How+to+use+ant+with+ANTLR3" rel="nofollow noreferrer">in this other post</a>.</p>\n\n<p>If you are using Eclipse, you will need to restart the IDE before it recognises the new task and you will also need to include <code>antlr3.jar</code> and <code>stringtemplate.jar</code> in your classpath (but <code>ant-antlr3.jar</code> is not necessary).</p>\n'}, {'answer_id': 21280786, 'author': 'ceving', 'author_id': 402322, 'author_profile': 'https://Stackoverflow.com/users/402322', 'pm_score': 1, 'selected': False, 'text': '<p>The most basic way to run Antlr is to execute the Antlr JAR:</p>\n\n<pre><code>&lt;project default="antlr"&gt;\n  &lt;target name="antlr"&gt;\n    &lt;java jar="antlr-4.1-complete.jar" fork="true"&gt;\n      &lt;arg value="grammar.g4"/&gt;\n    &lt;/java&gt;\n  &lt;/target&gt;\n&lt;/project&gt;\n</code></pre>\n\n<p>This is a bit slower, because it forks the JVM and it runs Antlr even if the grammar did not change. But it works in the same way with every Antlr version and does not need any special targets.</p>\n'}]
['https://Stackoverflow.com/questions/25481', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1190/']