[antlr-interest] FYI on how to build ANTLR (the "duplicate class: org.antlr.tool.ANTLRLexer" problem)

Kenneth Domino kenneth.domino at domemtech.com
Fri Apr 4 11:36:59 PDT 2008


Hi all,

I've been trying to build ANTLR version 3 from the sources provided in
the intermediate build archive antlr-2008-03-13.12.tar.gz (see
http://www.antlr.org/download/build/) using Ant.  However, I was running
into the same type of problem presented three times previously but
never explained why or how to fix it.  The error produced
by the build would be caused by compiling duplicate files:
"duplicate class: org.antlr.tool.ANTLRLexer".  See:

http://www.antlr.org/pipermail/antlr-interest/2007-September/023639.html
and 
http://www.antlr.org/pipermail/antlr-interest/2007-October/024192.html
and 
http://www.antlr.org/pipermail/antlr-interest/2007-December/025377.html
and http://www.antlr.org/wiki/pages/viewpage.action?pageId=732
and associated threads.

Unfortunately, the intermediate build archives contain several
generated ".java" files that should not be there if you intend to
build ANTLR via Ant.  This happens because "java antlr.Tool" was
performed within the src/org/antlr/tool/ and src/org/codegen/
directories on several ".g" files in those directories.  At the same time,
the Ant build copies these grammar files to the directory "codegen/",
generating another copy of the parser/lexer/.... Thus, the build now
has duplicates.  Why does it copy the ".g" files to "codegen/"?
I'm not sure.

Ideally, either these output ".java" files should be removed prior to 
archiving,
or the generated java files generated in-situ with the rest of the source
code.  The build.xml file should be fixed to prevent us users from
hitting the same problem over and over again. There are other ".g" files,
but these appear to be ANTLR v3 input, and are not part of the
build yet.

(Also, the build.xml also seems to reference property ${antlr2.jar}
but never defines it.  It this correct?)

To fix this manually, try:

gzip -d antlr-2008-03-13.12.tar.gz
tar -xvf antlr-2008-03-13.12.tar
cd antlr-2008-03-13.12
ant clean
rm -f src/org/antlr/tool/ANTLRLexer.java
rm -f src/org/antlr/tool/ANTLRLexer.smap
rm -f src/org/antlr/tool/ANTLRParser.java
rm -f src/org/antlr/tool/ANTLRParser.smap
rm -f src/org/antlr/tool/ANTLRTokenTypes.java
rm -f src/org/antlr/tool/ANTLRTokenTypes.txt
rm -f src/org/antlr/tool/ANTLRTreePrinter.java
rm -f src/org/antlr/tool/ANTLRTreePrinter.smap
rm -f src/org/antlr/tool/ANTLRTreePrinterTokenTypes.java
rm -f src/org/antlr/tool/ANTLRTreePrinterTokenTypes.txt
rm -f src/org/antlr/tool/AssignTokenTypesWalker.java
rm -f src/org/antlr/tool/AssignTokenTypesWalker.smap
rm -f src/org/antlr/tool/AssignTokenTypesWalkerTokenTypes.java
rm -f src/org/antlr/tool/AssignTokenTypesWalkerTokenTypes.txt
rm -f src/org/antlr/tool/DefineGrammarItemsWalker.java
rm -f src/org/antlr/tool/DefineGrammarItemsWalker.smap
rm -f src/org/antlr/tool/DefineGrammarItemsWalkerTokenTypes.java
rm -f src/org/antlr/tool/DefineGrammarItemsWalkerTokenTypes.txt
rm -f src/org/antlr/tool/TreeToNFAConverter.java
rm -f src/org/antlr/tool/TreeToNFAConverter.smap
rm -f src/org/antlr/tool/TreeToNFAConverterTokenTypes.java
rm -f src/org/antlr/tool/TreeToNFAConverterTokenTypes.txt
rm -f src/org/antlr/codegen/CodeGenTreeWalker.java
rm -f src/org/antlr/codegen/CodeGenTreeWalker.smap
rm -f src/org/antlr/codegen/CodeGenTreeWalkerTokenTypes.java
rm -f src/org/antlr/codegen/CodeGenTreeWalkerTokenTypes.txt

If you don't have junit, then remove the test subdirectory as well,
because the build file does not test this dependency:

rm -rf src/org/antlr/test/

Also, setting classpath is unnecessary, at least for the build,
because the build file sets classpath explicitly to include jar files
in directory "lib/".

Ken Domino



More information about the antlr-interest mailing list