[antlr-interest] Using Ant with Antlr3
Evan Driscoll
driscoll at cs.wisc.edu
Fri Oct 21 13:58:27 PDT 2011
I have a problem with ant and Antlr and I don't know what's going on.
I took the SimpleCalc grammar from
<http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3>
and put it into a directory with the following build.xml:
<project name="cminus" default="antlr" basedir=".">
<!-- Antlr3 is called here -->
<target name="antlr">
<antlr:ant-antlr3 xmlns:antlr="antlib:org/apache/tools/ant/antlr"
verbose="true"
outputdirectory="."
target="SimpleCalc.g"/>
</target>
</project>
(This is taken from about halfway down
<http://www.antlr.org/wiki/display/ANTLR3/How+to+use+ant+with+ANTLR3>
except that I replaced CMinus.g with SimpleCalc.g.)
I'm on a large network and there are machines with different
environments. On my machine, I have RHEL 5, and everything works
swimmingly. I run 'ant' and it builds SimpleCalcLexer.java and
SimpleCalcParser.java, I can compile those, and run those.
However, if I log into a machine with RHEL 6, then it doesn't work:
Buildfile: build.xml
antlr:
BUILD FAILED
/afs/cs.wisc.edu/u/d/r/driscoll/delete/antlr/build.xml:8: 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>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-/usr/share/ant/lib
-/u/d/r/driscoll/.ant/lib
-a directory added on the command line with the -lib argument
Total time: 0 seconds
The Antlr3 task is definitely in my ~/.ant/lib:
~/delete/antlr : ls ~/.ant/lib
antlr-3.4-complete.jar ant-antlr3.jar
and if I remove those it won't work on my own computer. Furthermore, I'm
running exactly the same code in the same environment in both cases; ~
is on a network drive and I just go to the same location.
If I run 'ant -diagnostics | grep -i antlr' I get this on my machine:
antlr-3.4-complete.jar (2388361 bytes)
ant-antlr3.jar (20889 bytes)
antlr : Not Available (the implementation class is not present)
user.dir : /afs/cs.wisc.edu/u/d/r/driscoll/delete/antlr
and this on the RHEL 6 machine:
ant-antlr.jar (5926 bytes)
antlr-3.4-complete.jar (2388361 bytes)
ant-antlr3.jar (20889 bytes)
user.dir : /afs/cs.wisc.edu/u/d/r/driscoll/delete/antlr
(there are also a couple hits in java.class.path)
The difference seems to be the presence of ant-antlr.jar -- which I
guess is for a previous version of Antlr? That is installed in a system
directory in RHEL 6:
~/delete/antlr : locate ant-antlr.jar
/usr/lib64/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-antlr.jar
/usr/share/ant/lib/ant-antlr.jar
/usr/share/java/ant/ant-antlr.jar
while locate does not find it on my RHEL 5 machine. (Disclaimer: locate
won't find stuff on our network drives.)
I'm not very familiar with Ant, so I'm not sure what's going on. Any
ideas of how to fix it?
Evan
More information about the antlr-interest
mailing list