2013-02-21 36 views
2

我的问题是关于使用ANT与ANTLR3。如何使用Antlr与antlr3

我下载蚂蚁antlr3并把它放在目录

eclipse-jee-helios-SR2-win32-x86_64\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib 

在我的build.xml地说:

`<path id="classpath"> 
    <pathelement location="${lib}/antlr-3.4-complete.jar"/> 
    <pathelement location="${lib}/ant-antlr3.jar"/> 
</ path>` 

    `<target name="antlr" depends="init"> 
    <antlr: ant-antlr3 xmlns: antlr = "antlib: org/apache/tools/ant/antlr" 
    target = "$ {Analyzers}/AnalizadorLexer.g" 
    outputdirectory = "$ {AnalizadoresBuild}" 
    verbose = "true"> 
    <classpath refid="classpath"/> 
    </ antlr: ant-antlr3> 
</ target>` 

运行ANTLR目标得到这个错误:

BUILD FAILED 
C: \ Users \ melmar \ Documents \ workspace \ PL \ Prac12 \ build_pol.xml: 68: Problem: failed to create task or type antlib: org/apache/tools/ant/antlr: ant-antlr3 
Cause: The name is undefined. 
Action: Check the spelling. 
Action: Check That any custom tasks/types Have Been declared. 
Action: Check That any <presetdef>/declarations have taken place <macrodef>. 
No types or tasks Have Been In This namespace defined yet 
This appears to be an antlib declaration. 
Action: Check That the Implementing library exists in one of: 

     -C: \ Users \ melmar \. Ant \ lib (don´t exist) 
     -a directory added on the command line argument With The-lib 

请问任何人都知道该怎么办?没有在课程路径中找到ant-antlr3

回答

1

我不使用antlr任务,而只是把ANTLR JAR为libs,然后做这样的事情:

<path id="classpath"> 

    <!-- more entries here --> 

    <fileset dir="lib"> 
     <include name="*.jar" /> 
    </fileset> 
</path> 

<target name="generate"> 
    <echo>generating the parser and lexer</echo> 
    <java classname="org.antlr.Tool" fork="true" failonerror="true"> 
     <arg value="-fo" /> 
     <arg value="path/to/output/generated/files" /> 
     <arg value="path/to/Grammar.g" /> 
     <classpath refid="classpath" /> 
    </java> 
</target> 
+1

我做同样的,但我也有它设置为自动下载ANTLR工具进入lib文件夹,如果它不在那里(或过期),所以我不必将库保存在源代码管理中。 – 2013-02-21 21:12:28

+1

示例'build.xml'包括自动下载和完整的最新检查:https://github.com/antlr/stringtemplate4/blob/master/build.xml – 2013-02-21 21:13:32

+0

@ 280Z28,这是一个整洁的想法。 “Ant-a-la-Maven”,所以要说:) – 2013-02-22 08:00:47