2

我的问题是关于将 ANT 与 ANTLR3 一起使用。

我下载了ant-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

4

1 回答 1

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>
于 2013-02-21T20:36:11.807 回答