I'm trying to call an Antlr task in my Ant build.xml as follows:
我正在尝试在Ant build.xml中调用Antlr任务,如下所示:
<path id="classpath.build">
<fileset dir="${dir.lib.build}" includes="**/*.jar" />
</path>
...
<target name="generate-lexer" depends="init">
<antlr target="${file.antlr.lexer}">
<classpath refid="classpath.build"/>
</antlr>
</target>
But Ant can't find the task definition. I've put all of the following in that dir.lib.build
:
但Ant无法找到任务定义。我已将所有以下内容放在dir.lib.build中:
- antlr-3.1.jar
- antlr-2.7.7.jar
- antlr-runtime-3.1.jar
- stringtemplate-3.2.jar
But none of those seems to have the task definition. (I've also tried putting those jars in my Ant classpath; same problem.)
但这些似乎都没有任务定义。 (我也尝试将这些jar放在我的Ant类路径中;同样的问题。)
6 个解决方案
#1
4
The current Antlr-task jar is available at http://www.antlr.org/share/1169924912745/antlr3-task.zip
当前的Antlr任务jar可从http://www.antlr.org/share/1169924912745/antlr3-task.zip获得。
It can be found on the antlr.org website under the "File Sharing" heading.
它可以在antlr.org网站的“文件共享”标题下找到。
#2
2
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.
你应该使用antlrall.jar jar。您可以继续将其放入Ant安装中,但这确实意味着它只适用于那个安装。我们检查jar并使用taskdef加载jar文件,这样当开发人员开始团队或移动到新计算机时,它不会成为开发人员的另一个步骤。
- Antlr http://ant.apache.org/manual/Tasks/antlr.html
- Using taskdef http://www.onjava.com/pub/a/onjava/2004/06/02/anttask.html
使用taskdef http://www.onjava.com/pub/a/onjava/2004/06/02/anttask.html
#3
2
I just got this working for myself. Took me an hour. ugh. anyway,
我刚刚为自己工作了。花了我一个小时。啊。无论如何,
Step 1: download ant-antlr3 task from
第1步:从中下载ant-antlr3任务
http://www.antlr.org/share/1169924912745/antlr3-task.zip
Step 2: copy to where ant can see it. My mac:
第2步:复制到ant可以看到的地方。我的mac:
sudo cp /usr/local/lib/ant-antlr3.jar /usr/share/ant/lib/
sudo cp /usr/local/lib/ant-antlr3.jar / usr / share / ant / lib /
my linux box:
我的linux盒子:
sudo cp /tmp/ant-antlr3.jar /usr/local/apache-ant-1.8.1/lib/
sudo cp /tmp/ant-antlr3.jar /usr/local/apache-ant-1.8.1/lib/
Step 3: make sure antlr2, antlr3, ST are in classpath. All in one is here:
第3步:确保antlr2,antlr3,ST在类路径中。一切都在这里:
http://antlr.org/download/antlr-3.3-complete.jar
Step 4: use in build.xml
第4步:在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>
Just added a faq entry:
刚刚添加了常见问题条目:
http://www.antlr.org/wiki/pages/viewpage.action?pageId=24805671
#4
1
The most basic way to run Antlr is to execute the Antlr JAR:
运行Antlr的最基本方法是执行Antlr JAR:
<project default="antlr">
<target name="antlr">
<java jar="antlr-4.1-complete.jar" fork="true">
<arg value="grammar.g4"/>
</java>
</target>
</project>
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.
这有点慢,因为它会分支JVM并且即使语法没有改变也会运行Antlr。但它与每个Antlr版本的工作方式相同,不需要任何特殊目标。
#5
0
On Ubuntu this should make it available:
在Ubuntu上,这应该是可用的:
sudo apt-get install ant-optional
sudo apt-get install ant-optional
#6
0
Additional info on top of what everybody else contributed so far:
到目前为止所有其他人贡献的其他信息:
The ant-optional
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 in this post. The method described by Terence is the best way to use the ANTLR3 task.
Ubuntu中的ant-optional包包含Ant 1.8.2附带的任务,这是ANTLR 2.7.2的任务,因此这将失败并出现本文所述的错误。 Terence描述的方法是使用ANTLR3任务的最佳方法。
If you do not have root access on a Linux machine, you can install the ant-antlr3.jar file in the Ant user directory: ~/.ant/lib
. Check with ant -diagnostics
whether ant-antlr3.jar is visible to Ant, as explained in this other post.
如果您在Linux计算机上没有root访问权限,则可以在Ant用户目录中安装ant-antlr3.jar文件:〜/ .ant / lib。检查ant -diagnostics是否对Ant可见ant-antlr3.jar,如另一篇文章中所述。
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 antlr3.jar
and stringtemplate.jar
in your classpath (but ant-antlr3.jar
is not necessary).
如果您正在使用Eclipse,则需要在识别新任务之前重新启动IDE,并且还需要在类路径中包含antlr3.jar和stringtemplate.jar(但不需要ant-antlr3.jar)。
#1
4
The current Antlr-task jar is available at http://www.antlr.org/share/1169924912745/antlr3-task.zip
当前的Antlr任务jar可从http://www.antlr.org/share/1169924912745/antlr3-task.zip获得。
It can be found on the antlr.org website under the "File Sharing" heading.
它可以在antlr.org网站的“文件共享”标题下找到。
#2
2
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.
你应该使用antlrall.jar jar。您可以继续将其放入Ant安装中,但这确实意味着它只适用于那个安装。我们检查jar并使用taskdef加载jar文件,这样当开发人员开始团队或移动到新计算机时,它不会成为开发人员的另一个步骤。
- Antlr http://ant.apache.org/manual/Tasks/antlr.html
- Using taskdef http://www.onjava.com/pub/a/onjava/2004/06/02/anttask.html
使用taskdef http://www.onjava.com/pub/a/onjava/2004/06/02/anttask.html
#3
2
I just got this working for myself. Took me an hour. ugh. anyway,
我刚刚为自己工作了。花了我一个小时。啊。无论如何,
Step 1: download ant-antlr3 task from
第1步:从中下载ant-antlr3任务
http://www.antlr.org/share/1169924912745/antlr3-task.zip
Step 2: copy to where ant can see it. My mac:
第2步:复制到ant可以看到的地方。我的mac:
sudo cp /usr/local/lib/ant-antlr3.jar /usr/share/ant/lib/
sudo cp /usr/local/lib/ant-antlr3.jar / usr / share / ant / lib /
my linux box:
我的linux盒子:
sudo cp /tmp/ant-antlr3.jar /usr/local/apache-ant-1.8.1/lib/
sudo cp /tmp/ant-antlr3.jar /usr/local/apache-ant-1.8.1/lib/
Step 3: make sure antlr2, antlr3, ST are in classpath. All in one is here:
第3步:确保antlr2,antlr3,ST在类路径中。一切都在这里:
http://antlr.org/download/antlr-3.3-complete.jar
Step 4: use in build.xml
第4步:在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>
Just added a faq entry:
刚刚添加了常见问题条目:
http://www.antlr.org/wiki/pages/viewpage.action?pageId=24805671
#4
1
The most basic way to run Antlr is to execute the Antlr JAR:
运行Antlr的最基本方法是执行Antlr JAR:
<project default="antlr">
<target name="antlr">
<java jar="antlr-4.1-complete.jar" fork="true">
<arg value="grammar.g4"/>
</java>
</target>
</project>
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.
这有点慢,因为它会分支JVM并且即使语法没有改变也会运行Antlr。但它与每个Antlr版本的工作方式相同,不需要任何特殊目标。
#5
0
On Ubuntu this should make it available:
在Ubuntu上,这应该是可用的:
sudo apt-get install ant-optional
sudo apt-get install ant-optional
#6
0
Additional info on top of what everybody else contributed so far:
到目前为止所有其他人贡献的其他信息:
The ant-optional
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 in this post. The method described by Terence is the best way to use the ANTLR3 task.
Ubuntu中的ant-optional包包含Ant 1.8.2附带的任务,这是ANTLR 2.7.2的任务,因此这将失败并出现本文所述的错误。 Terence描述的方法是使用ANTLR3任务的最佳方法。
If you do not have root access on a Linux machine, you can install the ant-antlr3.jar file in the Ant user directory: ~/.ant/lib
. Check with ant -diagnostics
whether ant-antlr3.jar is visible to Ant, as explained in this other post.
如果您在Linux计算机上没有root访问权限,则可以在Ant用户目录中安装ant-antlr3.jar文件:〜/ .ant / lib。检查ant -diagnostics是否对Ant可见ant-antlr3.jar,如另一篇文章中所述。
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 antlr3.jar
and stringtemplate.jar
in your classpath (but ant-antlr3.jar
is not necessary).
如果您正在使用Eclipse,则需要在识别新任务之前重新启动IDE,并且还需要在类路径中包含antlr3.jar和stringtemplate.jar(但不需要ant-antlr3.jar)。